Super Shortcuts : Top 15 GIT aliases to save your time & effort & boost productivity

What is GIT & GIT ALIAS and why to use them ?

GIT is presently the most popular distributed version control system (VCS) which is open-source that is used to track changes made to files and keep a history of those changes. It is specially useful when collaborating and working on large projects and helps to avoid conflicts and easy merging of code of multiple contributors. Git has a large and active community and you can also use it offline for tracking file changes. You can easily create backups of your code and recover from any accidental changes or data loss. It is a platform & programming language independant tool, so learning and using  GIT throughout your life is an excellent idea, imo.  !

Git aliases are custom shorthand versions of Git commands. They allow you to create shorter, easier-to-remember versions of Git commands. For example, instead of typing out the full command git status, you could create an alias git st that runs the same command.  You can create an alias by running the command git config –global alias.<alias_name> <git_command>. For example, to create an alias for git status, you would run :     git config –global alias.st status

Git aliases are stored in the Git configuration file and are available across all Git repositories on the same machine. With the above example, you could use the git st command from now on in any git repository to check the status of the working directory.

Top 15 most useful GIT alias you’ll love to use :

Now that you know how to create an alias, copy and use these super useful aliases often :-

1) GIT Log oneline (with all the useful details, great alias to use often) ➡️ git llog 


git config --global alias.llog "log --pretty='%C(yellow)%h %C(cyan)%ad %Cgreen%an%C(cyan)%d %Creset%s' --date=relative --date-order --graph"

2. GIT branch (display branches with latest commits, author & time) ➡️ git br


git config --global alias.br "branch --format='%(HEAD) %(color:yellow)%(refname:short)%(color:reset) - %(contents:subject) %(color:green)(%(committerdate:relative)) [%(authorname)]' --sort=-committerdate"

3) GIT hard reset to HEAD to clean uncommited changes  ➡️ git hh 


git config --global alias.hh "reset --hard HEAD"

4) git commit count summary (get details & number of commits by authors)  ➡️  git sl 


git config --global alias.sl "shortlog -sn --email"

5) git status  (get the status of the current branch)  ➡️  git s 


git config --global alias.s "status"

6) git checkout (switch to a new branch)  ➡️  git co 


git config --global alias.co "checkout"

7) git delete a branch  ➡️  git del <branchName> 


git config --global alias.del "branch -D"

8) Check last commit details with this alias ➡️ git last 


git config --global alias.last "log -1 HEAD --stat"

9) Git commit with a message with this alias ➡️  git cm 


git config --global alias.cm "commit -m"

10) git remote – Lists all configured remote repositories  ➡️   git rv 


git config --global alias.rv "remote -v"

11) The gl alias makes it easier to list all user configurations  ➡️  git gl 


git config --global alias.gl "config --global -l"

12) Search for text within your commits with this alias  ➡️ git se


git config --global alias.se "!git rev-list --all | xargs git grep -F"

13) Sync feature branch with master/main branch  ➡️ git pm 


git config --global alias.pm "pull origin master"

14) git cherry-pick a commit from a diferent branch  ➡️   git cp 


git config --global alias.cp "cherry-pick"

15) git undo last commit but keep the changes if last commit made was a mistake  ➡️  git uc 


git config --global alias.uc "reset --soft HEAD^"

Bonus:  If you want to get the list of alias you have created, use this command  ➡️  git al 


git config --global alias.al "config --get-regexp ^alias"

Overall, using GIT aliases can make working with Git more efficient and streamlined and allows you to focus on your work rather than on typing out long commands. So save and use these cool aliases while working with GIT.

Leave a Reply

Your email address will not be published. Required fields are marked *