Photo by Yancy Min on Unsplash

Create Shortcuts (Aliases) for Git

Filipe Good
The Startup
Published in
2 min readFeb 20, 2021

--

Git has a feature that “can make your git experience simpler, easier, and more familiar: aliases.

If you use git regularly this feature can really make a difference especially if you repeat a lot of git commands. Basically, you can create aliases (shortcuts) for everything that you might think! For example, instead of having to type “git commit — amend” you can create an alias and only type “git ca”! Or if you find yourself always typing at the end of the day “git commit — m ‘WIP’”, you can simply create an alias for that command and only type “git wip”

It’s fairly easy to set it up! You have two options: or you edit your .gitconfig file or you use git commands to do it.

Option 1

Open .gitconfig file:

  • Ubuntu:
nano ~/.gitconfig
  • Windows — the file is located in /etc/gitconfig. Open it with sublime or another text editor.

With the file open, you will have to add [alias] and then just start adding the aliases. Example:

[alias]
st = status
ci = commit
rio = rebase -i origin/v1.0 # git rebase -i origin/v1.0

For the last example, instead of typing ‘git rebase -i origin/v1.0', you just need to typegit rio’

Option 2

Open your terminal and use git config command to set aliases. Example:

$ git config --global alias.st status
$ git config --global alias.ci commit
$ git config --global alias.rio "rebase -i origin/v1.0"

Note: Use double quotes when the command has spaces (like the last example)

This feature can also be very useful for creating commands that you think should exist!

Example 1:

At the end of the day, you always type “git commit — m ‘WIP’? Just add this alias:

wip = commit -m "WIP"

Now, you will only need to type “git wip”

Example 2:

A very useful command that I would like git to have is “undo”. Basically, a command that would undo all changes due to be committed. Well, we can create one :)

undo = reset --soft HEAD^

Now, I have my “own” custom command: git undo

Now that you know this simple trick, you just have to be creative! Think of the commands that you use every single day and create aliases for them. You can take some inspiration from this page — https://git.wiki.kernel.org/index.php/Aliases#Aliases

--

--