Using Git aliases to improve your productivity.
Rukundo Kevin
Posted on May 8, 2023
Git is a powerful tool but can be challenging to learn and remember commands for frequent use.
This is where Git alias comes in handy, Git aliases are user-defined shorthand for a sequence of commands that can be easily executed by typing a short name, which gets translated into the full command.
They are of 2 types.
- Git aliases and
- Shell Aliases
Creating Git Aliases
open ~/.gitconfig in your favorite editor- for my case VSCode.
code ~/.gitconfig
Then add your alias.
Before creating your alias, it is important to ensure that it does not conflict with any existing git commands, as this can cause issues.
[alias]
s = status -s
Now you can just type git s
to view your git status.
My Aliases
Here are some of Aliases that use.
s = status
cnv = commit --no-verify
cane = commit --amend --no-edit
aa = add .
p = push
pf = push --force
la = log --oneline --decorate --graph --all
l = log --oneline --decorate --graph
rl= ref log
la = "!git config -l | grep alias | cut -c 7-"
But these are just a few which are useful for me, if you need to explore more Must Have Git Aliases
On
Shell Aliases
Unlike Git Aliases, Shell alias are stored in ~/.bashrc or ~/.zshrc
Creating Shell aliases.
open ~/.zshrc or ~/.bashrc in your editor.
Then add your alias in this format.
alias gs='git status -s'
So, when you are going to check, just write gs without the Git prefix.
One thing to take into account though before creating your alias is to make sure that your alias doesn't collide with the already existing git command which can mess
Hope Aliases makes your development more productive and faster.
If you find the content useful, you can follow me on Github or Twitter
References.
https://gist.github.com/mwhite/6887990
https://git-scm.com/book/en/v2/Git-Basics-Git-Aliases
Posted on May 8, 2023
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.