Skip to content

Instantly share code, notes, and snippets.

@cbilson
Last active August 22, 2017 08:50
Show Gist options
  • Save cbilson/c4179f2b46a06bdfdd1f to your computer and use it in GitHub Desktop.
Save cbilson/c4179f2b46a06bdfdd1f to your computer and use it in GitHub Desktop.
My .gitconfig
[user]
email = cbilson@microsoft.com
name = Chris Bilson
[core]
editor = "'C:/ProgramData/Chocolatey/bin/emacsclientw.exe' --quiet --alternate-editor=notepad $*"
[diff]
tool = bc4
[difftool "bc4"]
cmd = \"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\"
[merge]
tool = bc4
[mergetool "bc4"]
cmd = \"c:/program files (x86)/beyond compare 4/bcomp.exe\" \"$LOCAL\" \"$REMOTE\" \"$BASE\" \"$MERGED\"
trustExitCode = true
[credential]
#helper = !'C:\\Users\\Chris\\AppData\\Roaming\\GitCredStore\\git-credential-winstore.exe'
[color]
diff = auto
branch = auto
status = auto
interactive = auto
ui = auto
[status]
relativePaths = true
[rerere]
enabled = true
[push]
default = tracking
[branch]
autosetupmerge = true
[alias]
amend = commit --amend
br = branch
c = commit -v
cb = checkout -b
cim = commit --message
co = checkout
cp = cherry-pick
l = log --no-merges
lg = log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr)%Creset' --abbrev-commit --date=relative
lc = log ORIG_HEAD.. --stat --no-merges
lol = log --graph --decorate --pretty=oneline --abbrev-commit
lola = log --graph --decorate --pretty=oneline --abbrev-commit --all
ll = log --graph --date=short
m = checkout master
pull = pull --ff-only
rb = rebase
rbc = rebase --continue
rbi = rebase --interactive
rbs = rebase --skip
send-note = send-email --annotate
st = status
staged = diff --cached
# commits not pushed to $1
unpushed = cherry -v
# what tag contains the sha
whatrelease = name-rev --name-only
# what branch contains the sha
contains = branch --contains
#from http://serverfault.com/questions/175052/how-to-tell-which-local-branch-is-tracking-which-remote-branch-in-git
upstream = rev-parse --symbolic-full-name --abbrev-ref HEAD@{upstream}
#also from http://serverfault.com/questions/175052/how-to-tell-which-local-branch-is-tracking-which-remote-branch-in-git
tbranch = branch -vv
# what got pushed to master in the last hour
# based on http://stackoverflow.com/questions/3357219/expose-the-date-a-commit-was-pushed-to-a-repository
justpushed = log origin/master@{\"1 hour ago\"}..origin/master --
# log everything with $1 string in the diff
timegrep = log -S
# like above, but show the diff
diffgrep = log -p -S
# search logs for a bugzilla like number
findbug = !sh -c 'git log --grep=^$1:' -
# search for a pattern in branch names, file names, or file contents
#find = "!f() { ((git branch -a ; git ls-files) | grep $1); git grep $1 }; f"
find = "!f() { (git branch -a ; git ls-files) | grep $1; GIT_PAGER=cat git grep $1; }; f"
# show what tag/release a bug was part of
#bugrelease = "!sh -c 'git name-rev --tags --name-only $(git log --grep ^$1: --pretty=\"format:%H\"\n")' -
# from https://gist.github.com/492227
lost = "!git fsck | awk '/dangling commit/ {print $3}' | git show --format='SHA1: %C(yellow)%h%Creset %f' --stdin | awk '/SHA1/ {sub(\"SHA1: \", \"\"); print}'"
# show a log without the formating, occasionaly handy for c&p
rawlog = log --format=\"format:commit %H%nAuthor:%an%n%n%B%n\"
# show a list of branches sorted by time of last commit
brage = "!f() { git for-each-ref --sort=committerdate refs/heads $1 --format=\"%(refname:short)\" ; }; g() { for C in $(f $1) ; do git show -s --pretty=format:\"%Cgreen%ci %Cblue%cr%Creset $C\" \"$C\" -- ; done; }; g "
# show remote branches as well
brageall = !git brage refs/remotes
tbrage = "!f() { git for-each-ref --sort=committerdate refs/heads $1 --format=\"%(refname:short)\" ; }; g() { for C in $(f $1) ; do UP=$(git rev-parse --symbolic-full-name --abbrev-ref $C@{upstream} 2> /dev/null); TRACKING=$?; UP=\"-> $UP \"; if [ $TRACKING -ne 0 ] ; then UP=\"\"; fi; git show -s --pretty=format:\"%Cgreen%ci %Cblue%cr%Creset $C $UP\" \"$C\" -- ; done; }; g "
tbrageall = !git tbrage refs/remotes
# show a list of tags sorted by when they were tagged
tagage = !sh -c 'git for-each-ref --sort=taggerdate refs/tags --format=\"%(refname:short)\"'
# show a list of tags sorted by `sort` version compare (ie, more or less rpmvercmp)
tagsort = !sh -c 'git tag -l $1 | sort --version-sort'
# show a list of every branch and show their latests commit, sorted by last commit
brlog = "!sh -c 'for C in $(git for-each-ref --sort=committerdate refs/heads --format=\"%(refname:short)\") ; do git show -s --pretty=format:\"%Cgreen%ci %Cblue%cr%Creset $C\" \"$C\" -- ; git show --stat -s $C ; echo; done'"
brlogremote = "!sh -c 'for C in $(git for-each-ref --sort=committerdate refs/remotes/origin --format=\"%(refname:short)\") ; do git show -s --pretty=format:\"%Cgreen%ci %Cblue%cr%Creset $C\" \"$C\" -- ; git show --stat -s $C ; echo; done'"
# show a list of last change in each branch of a given path
# roly poly fileheads
fileheads = "!sh -c 'for C in $(git for-each-ref --sort=committerdate refs/heads --format=\"%(refname:short)\"| tac) ; do git show -s --pretty=format:\"%Cgreen%ci %Cblue%cr%Creset $C\" \"$C\" -- ; git --no-pager log -p -1 $C -- $0; echo; done'"
yesterday="log --author=cbilson@pobox.com --all --decorate --since=yesterday"
#yesterday = "!sh -c 'for C in $(git for-each-ref --sort=committerdate refs/heads --format=\"%(refname:short)\"| tac) ; do echo git --no-pager log --since=yesterday -p -1 $C -- $0; done'"
# not useful itself, but handy to remember for use in scripts
thisbranch = rev-parse --abbrev-ref HEAD
# url of origin, about 99% of what I use git config --list for
cloneurl = config --get remote.origin.url
# from https://github.com/cypher/dotfiles/blob/master/gitconfig
ls-ignored = ls-files --exclude-standard --ignored --others
# as per https://twitter.com/jrbowes/status/304942580133679105
# delete all local branches that have been merged into master
#
# note, "git branch --merged master" will helpfully include master itself
# as a branch that has been fully merged to master. Gee, thanks git.
#
# So for sanity, filter out current branch and anything named master
#
# Also note -d won't delete branches that aren't merged to their tracking
# branch. Use -D if you dont care.
#
# See also 'git remote prune
purge = !git branch -d $(git branch --merged master | grep -v -e '*' -e 'master')
# mostly from http://stackoverflow.com/questions/67699/how-do-i-clone-all-remote-branches-with-git
#binge = "!sh -c 'for BRANCH in $(git branch -a | sed -n \"\=/HEAD$=d; \=/master$=d;s= remotes/==p\") ; do branch --track ${BRANCH##*/} $BRANCH ; done' "
# ignore local changes to a file
ignore = update-index --assume-unchanged
# http://sandofsky.com/blog/git-workflow.html
# merge code but not history to manually recommit
# for emergency use only
bankrupt = merge --squash
# https://github.com/wadey/dotfiles/blob/master/gitconfig
# check if a branch has been merged into the current HEAD
# if on master, "git merged topic" will tell you if topic
# has been merged
merged = !sh -c 'git rev-list HEAD | grep $(git rev-parse $0)'
# https://github.com/prabirshrestha/ProfilesAndSettings/blob/master/.gitconfig
# show tags and any tag annotation (tito adds tag annotations for example)
tags = tag -n1 -l
# https://github.com/aspiers/git-config/blob/master/bin/git-cdup
# could be useful for scripts
cdup = rev-parse --show-cdup
# https://github.com/SixArm/sixarm_git_gitconfig/blob/master/gitconfig-alias.txt
# Show the date of the first commit
log-first-date = !git log --date-order --date=iso --pretty=\"format:%ad\" --reverse | head -1
# https://github.com/SixArm/sixarm_git_gitconfig/blob/master/gitconfig-alias.txt
# Editing and adding conflicted files: when we get many merge conflicts
# and want to quickly solve them using an editor, then add the files.
edit-unmerged = "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; $EDITOR `f`"
add-unmerged = "!f() { git ls-files --unmerged | cut -f2 | sort -u ; }; git add `f`"
# from https://github.com/SixArm/sixarm_git_gitconfig/blob/master/gitconfig-alias.txt
# Thanks to jtolds on stackoverflow
remote-ref = "!bash -c ' local_ref=$(git symbolic-ref HEAD); local_name=${local_ref##refs/heads/}; remote=$(git config branch.\"#local_name\".remote || echo origin); remote_ref=$(git config branch.\"$local_name\".merge); remote_name=${remote_ref##refs/heads/}; echo remotes/$remote/$remote_name'"
# also from https://github.com/SixArm/sixarm_git_gitconfig/blob/master/gitconfig-alias.txt
# Thanks to jtolds on stackoverflow
rebase-recent = !git rebase -i $(git remote-ref)
# from http://blog.blindgaenger.net/advanced_git_aliases.html
alias = !git config --list | grep 'alias\\.' | sed 's/alias\\.\\([^=]*\\)=\\(.*\\)/\\1\\ = \\2/' | sort
# http://superuser.com/a/169696
# prettier than my version of this
# doesn't really work, should probably use git for-each-ref
#heads = !"git log origin/master.. --format='%Cred%h%Creset;%C(yellow)%an%Creset;%H;%Cblue%f%Creset' | git name-rev --stdin --always --name-only | column -t -s';'"
pconfig = config -f .git/config
# for "reverse" bisects, where you are trying to find the
# first working commit
bisect-fixed = bisect bad
bisect-unfixed = bisect good
# from https://gist.github.com/awood/11189030
oldest-ancestor = !bash -c 'diff --old-line-format='' --new-line-format='' <(git rev-list --first-parent "${1:-master}") <(git rev-list --first-parent "${2:-HEAD}") | head -1' -
branchdiff = "!f() { head=${1:-HEAD} ; ancestor=`git oldest-ancestor master $head` ; git diff $ancestor..$head ; }; f"
visual-branchdiff = "!f() { head=${1:-HEAD} ; ancestor=`git oldest-ancestor master $head` ; git diff --name-only $ancestor..$head | xargs diffuse -s -r $ancestor ; }; f &"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment