From the inception of git, it is the favorite version control system for most of the developers. Git is very flexible to manage the development workflow and collaborate with other developers.

Most modern IDEs are now equipped with inbuilt git user interface integration so the developers can do the git operations within the IDEs. Still, many developers depend or love to do git operation using command line only. And this article is intended for those who love to do git operations using the command line.

Set up aliases in git

git config command will help you to achieve this very easily.

Below is the basic structure for setting the git aliases.

$ git config --global alias.my_alias "git_commnad" 

Here are a couple my favourite git aliases which you can re-use.

$ git config --global alias.co  checkout 
$ git config --global alias.b branch
$ git config --global alias.s status
$ git config --global alias.c commit
$ git config --global alias.fo fetch origin

The above examples will enable the following functionalities

  • git co, this command will be the alias for git checkout.
  • git b, this command will be the alias for git branch.
  • git s, this command will be the alias for git status.
  • git c, this command will be the alias for git commit.
  • git fo, this command will be the alias for git fetch origin

Also you can Create aliases for non-git commands using the same method

For aliasing non-git commands follow the same procedure
and prefix your non-git command with an !

For example, if you want to create an alias for gitk; which is an application used to get the visual representation of your git repo history.

$ git config --global alias.view '!gitk' 

How git remembers the command aliases

All the aliases created will be stored in the .gitconfig file.
Here is how my .gitconfig looks.

[alias]
        co = checkout
        b = branch
        s = status
        c = commit
        fo = fetch
        view = !gitk

Since we created the aliases in global, it will be stored in your global config file.
To view the same run below command

 vim $HOME/.gitconfig 

Likewise, we can create aliases for any other command in git.