Different from alias
bound to the bash-liked shell of the system. Git aliases are more like a shorter command to be typed command started with git <alias>
.
Aliases also have the scope limited to local project or global configuration. The configurations would be stored at .gitconfig
.
Alias creation and usage
1# CREATE AN ALIAS
2$ git config --global alias.<alias-name> "<git command>"
3
4# USE AN ALIAS
5$ git <alias-name> <more optional arguments>
Helpful Aliases
Commonly used shorthand commands (to be continuously added…):
1# UNDO LAST COMMIT
2$ git config --global alias.undo "reset --soft HEAD^"
3
4# AMEND STAGED CHANGES TO LAST COMMIT (keep commit message)
5$ git config --global alias.amend "commit --amend --no-edit"
6
7# COMPACTER STATUS OUTPUT
8$ git config --global alias.st "status -sb"
9
10# COLORED LOG WITH GRAPH
11$ git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset'"
12
13# REMOVE ALL MERGED BRANCHES
14$ git config --global alias.rmb "!git branch --merged | grep -v '*' | xargs -n 1 git branch -d"
15
16# RANK CONTRIBUTERS
17$ git config --global alias.rank "shortlog -n -s --no-merges"
18
19# LIST RECENT VISITED BRANCHES
20$ git config --global alias.recent "for-each-ref --sort=-committerdate refs/heads/ --format=\"%(committerdate:short) %(refname:short)\" --count=10"
21
22# COUNT COMMITS IN CURRENT BRANCH
23$ git config --global alias.count "rev-list --count HEAD"
References
- 10 Git Tips To Save Time And Improve Your Workflow (https://belief-driven-design.com/10-git-tips-dfe5d6a72ce)
- Git Alias | Atlassian Git Tutorial (https://www.atlassian.com/git/tutorials/git-alias)
Thanks for reading!
comments powered by Disqus