Sunday, 11 April 2021

How to create aliases for git commands used frequently?

We can create aliases, shorter versions for git commands, using git config command.

git config --global alias.<shorter_name> <command>

If the command is having multiple words, then you single quotes

git config --global alias.<shorter_name>     '<command>    <attribute1> <attr2> .... '

Examples:

For checkout command use:

git config --global alias.co checkout

For commit command use:

git config --global alias.ct commit

For branch command use:

git config --global alias.br branch

For status command use:

git config --global alias.st status

For pull complete command (multiple words) use:

git config --global alias.plm 'pull origin master'


Note: you can check all the aliases & other config options using

git config --global --list

Output:

alias.co=checkout

alias.br=branch

alias.ct=commit

alias.st=status

alias.plm=pull origin master