Skip to main content

Command Palette

Search for a command to run...

Git Aliases

Published
2 min read

I'm a big fan of git aliases, and use some every day. If you're not familiar, then check them out.

Adding an alias is simple (XXX = the alias; YYY = the command it is an alias for):

git config --global alias.XXX YYY

The first alias to add, is an alias that allows you to easily see your aliases:

git config --global alias.aliases "config --get-regexp alias"

Then there's some basic shortcuts to allow for more concise commands:

git config --global alias.st status
git config --global alias.co checkout
git config --global alias.ci commit
git config --global alias.wl worklog
git config --global alias.br branch

Then there are some commands that make life a little easier:

git config --global alias.aa "add ."
git config --global alias.aaa "add --all"
git config --global alias.new "push -u origin HEAD"
git config --global alias.last "log -1 HEAD"
git config --global alias.rh "reset --hard"
git config --global alias.prune "remote prune origin"
git config --global alias.logtree "log --graph --oneline --decorate --all"

Then we can get bash involved and get some more complex custom commands in to the mix. I find it a lot easier to add these by hand to the .gitconfig file instead of fretting about escaping the commands properly.

clear = !"git rh && git clean -f"

com = "!sh -c \"bug=`git symbolic-ref HEAD|sed s#refs/heads/##`; git commit -m \\\"\\${bug}: $1\\\" $2 $3 $4 $5\""

boom = !git aa && git com \"$1\" && git new && echo \"BOOM!!!\"

wipe = !git aaa && git commit -qm \"WIPE SAVEPOINT\" && git reset HEAD~1 --hard

maintain = !git prune && git branch -vv | awk '{print $1,$4}' | grep 'gone]' | awk '{print $1}' | xargs git branch -D