How to Create Git Aliases
For easy access to frequently used git commands, set up Git aliases. While in some cases shell aliases might make sense, Git also has built in support for defining aliases. For example, you could create an alias for “git commit” to
$ git ci
This also allows you to pass flags for options you commonly like to use, for example, you could alias “git commit -a” to
$ git cia
Setting them up is easy, just edit the .gitconfig file in your home directory (or create it if it doesn’t exist yet). Under the [alias] section header, add the alias and the command you want it to execute. Here’s an example:
[alias]
ci = commit
cia = commit -a
co = checkout
cob = checkout -b
So if you want to checkout a new branch, just type
$ git cob mybranch
and to commit with all edits added, run
$ git cia
Another important thing to note, is that you can pass any normal flag when using an alias. For example, if your .gitconfig file was setup as above, and you wanted to see a verbose diff of your changes when committing, then just run
$ git ci -v
One last tip, if you want to double check what a particular alias will run without opening the .gitconfig file, just type
$ git <alias> --help
and Git will show you the command and any flags executed with the specified alias.