All Articles

My git aliases

Photo by Yancy Min on Unsplash unsplash-logoYancy Min

tl;dr: All the aliases are here. Feel free to choose some (or all) and add to your list. They’re not necessarily mine, many I found around the internet, some with customizations and some “as is”. I wish I could give proper credits for all of them, but I can’t remeber where I saw them in the first place.

For those who prefer using the terminal to control the repository workflow, git commands might look verbose after hundreds of executions. That two or three seconds choosing and typing the right parameters sum up at the end of the day, but it is not only that: It can steal a bit of your attention and you will take some time to focus on your task again. Git aliases are in town to let you tackle this issue and get back those precious seconds!

If you don’t know how this work, git allows you to write aliases for the standard commands. So you can sum up all common parameters, options, formats in one simple abbreviation with a couple characters. So when you need to type them 30 times a day you can be more succinct:

$ git config --global alias.cb 'checkout -b'
$ git cb new_branch
Switched to a new branch 'new_branch'

If you don’t use the —global option the aliases are going to be stored in your user config, not system wild. You can also put them directly on your ~/.gitconfig:

[alias]
        cb = 'checkout -b'

Now you undestand how it works, you can look up all the usual aliases I use in all my workstations:

git config --global alias.co checkout
git config --global alias.cb 'checkout -b'
git config --global alias.c 'commit'
git config --global alias.cam 'commit -am'
git config --global alias.b 'branch' # only local branches
git config --global alias.ba 'branch -a' # include remote branches
git config --global alias.s 'status -sb' # my favorite, it should be the 'status' standard
git config --global alias.l 'log --pretty=format:"%h %ad | %s%d [%an]" --date=short' # simple hist
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit" # complex graph with more info

Conclusion

Git aliases can improve your productivity by letting you focus on what is really important. Those are some simple git aliases that I use a lot, but you can try it out, change parameters and see what is the best fit for you. There is not a consensus on the best abbreviations as well. Some people try to summarize the parameters, some people like funnier combinations. It is up to you decide :)