created: 25.10.2018 10:07

edited: 30.10.2018 08:48


If you don’t want to type the entire text of each of the Git commands, you can easily set up an alias for each command using git config. Here are a couple of examples you may want to set up:

git config --global checkout
git config --global branch
git config --global commit
git config --global status

This technique can also be very useful in creating commands that you think should exist. For example, to correct the usability problem you encountered with unstaging a file, you can add your own unstage alias to Git:

git config --global alias.unstage 'reset HEAD --'

git unstage fileA // is the same as
git reset HEAD -- fileA

As you can tell, Git simply replaces the new command with whatever you alias it for. However, maybe you want to run an external command, rather than a Git subcommand. In that case, you start the command with a ! character. This is useful if you write your own tools that work with a Git repository. We can demonstrate by aliasing git visual to run gitk:

git config --global alias.visual '!gitk'