When working with the Git CLI, we often type a lot of command lengthy and repetitive. However, Git has Alias support, so it is very useful and saves typing time, helping us to increase productivity and efficiency.
What is Git Alias?
alias (noun): alias, nickname, nickname.
Basically Git Alias provides the ability to save a command with a different name (may be shorter or longer).
How to add Git Alias
There are 2 ways to add:
1 / Add to git config file: git config --global --edit
1 2 3 | [alias] co = checkout |
2 / Use Git CLI: git config --global alias.co checkout
How to use Git Alias?
After running one of the two commands above, we can now use Git Alias for the checkout command. Instead of typing git checkout
, now just type git co
.
Parameters to commands you use as you normally would, for example, to create a new branch will be: git co -b new-branch
List of commonly used alias
:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | # ... [aliases] # basic commands co = checkout br = branch st = status ci = commit # quick --fixup commit # ex: git fixup [hash] fixup = commit --fixup # quick --amend commit # ex: git amend [hash] amend = commit --amend # quick rebase on top of latest remote master # ex: git rom rom = rebase origin/master # safe force push if no one else pushed yet # ex: git pf # note: suggestion to use whenever "git rom" pf = push --force-with-lease # safe switch to another branch # ex: "git switch another-branch" # note: it will stage all changes and save to stash before checkout switch = !git add . && git stash save WIP && git co # compact commit history flat view # ex: "git ls" # ex: "git ls -5" - show last 5 commits # see: https://git-scm.com/docs/pretty-formats for more details ls = log --pretty=format:'%C(yellow)%h %C(green) %cr%C(red) %d%C(reset) %s%C(bold blue) <%an>%C(reset)' --abbrev-commit # compact commit history graph view # ex: "git lg" # see: https://git-scm.com/docs/pretty-formats for more details lg = log --pretty=format:'%C(yellow)%h %C(green) %cr%C(red) %d%C(reset) %s%C(bold blue) <%an>%C(reset)' --abbrev-commit --graph # compact statistics for certain commit # ex: "git stat [hash]" stat = show --stat --oneline |
Above is how to use Git Alias I just learned, through the process of using it, I feel quite effective. Hope it is also helpful to you.
Source: https://towardsdev.com/speed-up-your-git-workflow-with-aliases-2d9e69ff5535