Skip to content

Instantly share code, notes, and snippets.

@agargiulo
Last active March 3, 2023 07:57
Show Gist options
  • Save agargiulo/6211380390050f0df087381522e900bb to your computer and use it in GitHub Desktop.
Save agargiulo/6211380390050f0df087381522e900bb to your computer and use it in GitHub Desktop.
my git config, more or less
[user]
name = Person Name
email = you_rock@example.com
# I love Vim. Vimdiff is amazing. This combined with `merge.conflictstyle = diff3`
# makes for fun 4 pane vim sessions that make merge headaches almost all go away
[diff]
tool = vimdiff
compactionHeuristic = true
[alias]
# This may or may not work, I can't remember.
shorten ="!sh -c 'curl -i https://git.io -F url=$1' -"
# REALLY AMAZING LOOKING git log. Colorful, with a graph, and decorated commits (Shows branch and remote/branch headers on commits that are branch HEADs)
lol = log --graph --pretty=format:'%C(auto)%h %C(white)(%p) - %C(yellow)[%C(magenta bold)%aN%C(reset)%C(yellow)]%C(reset)%C(auto) -%d %s %C(yellow)( C: %C(green)%cd %C(yellow)A: %C(green)%ad%C(yellow no-bold))%C(reset)' --abbrev-commit --date=auto:human --color
# Same as above but shows gpg signatures on commits
lols = !git lol --show-signature
# Similar to `git lol` but it shows all branches, not just the current branch. Sometimes very useful for dealing with merges and PRs
lola = !git lol --all
# lolas : lola :: lols : lol
lolas = !git lola --show-signature
lolsa = !git lols --all
# Fun stuff with the reflog because I need to find lost commits from time to time
lrl = log --reflog --pretty=format:'%C(auto)%h - %C(yellow)[%C(magenta bold)%aN%C(reset)%C(yellow)]%C(reset)%C(auto) -%d %s %C(yellow)( C: %C(green)%cd %C(yellow)A: %C(green)%ad%C(yellow no-bold))%C(reset)' --abbrev-commit --date=relative --color --graph
# Pass this a commit range (origin/master...HEAD) to see commits different between them
l2r = log --left-right --graph --cherry-pick --oneline
# Based on this SO answer: https://stackoverflow.com/a/25777221
ltag = log --pretty=format:'%C(auto)%h (%p) - %C(yellow)[%C(magenta bold)%aN%C(reset)%C(yellow)]%C(reset)%C(auto) -%d %s %C(yellow)( C: %C(green)%cd %C(yellow)A: %C(green)%ad%C(yellow no-bold))%C(reset)' --abbrev-commit --date=relative --color --tags --no-walk
# These are just shorthands since I got lazy and such.
st = status
sh = show
cb = rev-parse --abbrev-ref
co = checkout
sw = switch
d = diff
dc = diff --cached
dcc = diff --color --cached
rem = remote
up = fetch --all --prune --prune-tags
# This will show you where the root of the git repo lives. Useful for things like:
# cd `git root`
root = rev-parse --show-toplevel
# SHA of the root commit. Useful: `git rc | git name-rev --stdin`
rc = rev-list --max-parents=0 HEAD
gitdir = rev-parse --git-dir
# Get the short sha of a commit (HEAD?)
short = rev-parse --short=8
# Used when signing commits. Same as `git commit --gpg-sign[=<keyid>]`
commits = commit -S
# Stands for "sign last", so `git sl` will ammed the last commit with a gpg signature.
sl = commit --amend -C HEAD -S
# Ammend last: rewrite the HEAD commit with whatever changes you made with git add/rm/etc
# Keep in mind, using this or the sl alias will change history,
# so `git push --foce ...` is needed if you've already pushed before running this command
aml = commit --amend -C HEAD
ic = commit --allow-empty -m 'root commit'
assume = update-index --assume-unchanged
# undo above hack (If you need to actually update the file
unassume = update-index --no-assume-unchanged
# List files that git thinks will not change
assumed = "!git ls-files -v | grep ^h | cut -c 3-"
# generate commit graph in dot format
# ex: git graphviz HEAD~50..HEAD | dot -o head_50.png -Tpng
graphviz = "!f() { echo 'digraph git {' ; git log --pretty='format: %h -> { %p }' \"$@\" | sed 's/[0-9a-f][0-9a-f]*/\"&\"/g' ; echo '}'; }; f"
# Count of all the commits in the repo
count = rev-list --count --all
# git reset HEAD --hard # UNDO
unreset = fsck --lost-found
tags = tag -l --sort=v:refname
cisk = push --push-option=ci.skip
# Basically makes the colors for git diff and status and branch look a ton better than the defaults
# These are the recommended colors from `diff-so-fancy --colors`
[color]
ui = true
[color "branch"]
current = green
local = yellow
remote = red
[color "diff"]
meta = 227
frag = magenta bold
old = red bold
new = green bold
commit = 227 bold
whitespace = red reverse
[color "status"]
added = green
changed = yellow
untracked = red
[color "diff-highlight"]
oldNormal = red bold
oldHighlight = red bold 52
newNormal = green bold
newHighlight = green bold 22
# This sets a global excludes file.
# Useful for ignoring editor files instead of cluttering individual repo gitignores with that crap
[core]
pager = delta
excludesfile = ~/.gitignore
[delta]
plus-color = "#012800"
minus-color = "#340001"
syntax-theme = OneHalfDark
[interactive]
diffFilter = delta --color-only
# current - push the current branch to update a branch with the same name on the receiving end.
# Works in both central and non-central workflows.
# See the push.default section of https://git-scm.com/docs/git-config.html for other choices here
[push]
default = current
# This is useful for caching creds for http/https remotes. So you don't have to type it every time
# but also don't have to save them in the plaintext .git/config files
[credential]
helper = cache
# This adds a "merged common ancestors" section to merge conflicts
# This is super nice since it shows you how each side of the merge changed,
# so resolving merges is easier.
# http://psung.blogspot.com/2011/02/reducing-merge-headaches-git-meets.html
[merge]
conflictstyle = diff3
# Use this to automatically rebase when you make a commit BEFORE you run `git pull..`
# so that you don't have a ton of merge commits when you commit then pull
# You also need to add `rebase = true` to the [branch "some_branch"] section in .git/config
# of each repo for whatever branch (This setting will add that for you for new repos I believe
[branch]
autosetuprebase = always
# Show patch(es) to be committed when editor is opened for commit message.
# Change to 2 (from true?) to also show unadded changes after the staged changes
# https://git-scm.com/docs/git-commit#git-commit--v
[commit]
verbose = true
# vim : set ft=gitconfig noet :
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment