Improving Your Git Productivity with Aliases
By: Gideon Caller
Tags: Gitconfig, Self Improvement, Git, Technology, Productivity

One of the main concerns for developers who want to start using Git from the command line is that it’s slow. It may also feel slow if you compare it to a Git GUI that groups multiple Git commands into a single action. This is where Git aliases can come handy.

If you’ve never used aliases you basically need to create a file named gitconfig to store these aliases (if you’ve never done it before check setting up gitconfig). Although gitconfig allows you to do many things, we’ll be focusing on aliases (if you’ve never used Git aliases before check setting up Git aliases).

Let’s start by looking at a very basic but useful alias for git status. Add st = status to your gitconfig file. We can now use git st instead of the slightly longer git status .

Before we dive into some more useful aliases I would like to share my rules for what goes into my personal .gitconfig .

Only add aliases for commands you know — otherwise, there’s less chance you will actually use them. Furthermore, you don’t grow as a developer when you’re using things you don’t understand.

Only add commands after you’ve used them multiple times to avoid littering your Gitconfig — this also verifies you have these commands in your muscle memory.

Try to follow a convention & be consistent with your aliases — this makes remembering your aliases a breeze. It also speeds pulling these aliases out of your head.

With that out of the way, let’s start (note that I added some documentation to make the gists easier to read)

Now we can use these from the command line

It’s worth noticing the conventions I used. If, for example, I need to use some “add” command, know it will start with an a which makes it easier to remember.

At some point I started feeling like typing git is actually longer than at least some of my aliases so I decided to create a zsh alias in my zshrc that goes like this: alias g="git" .

This made all my commands even shorter (try to think how many times a day you’re typing git into your terminal).

Let’s look at some more useful aliases:

At this point, I hope you are starting to see how useful these aliases can be. Another awesome thing about .gitconfig is that it allows you to add bash commands:

Our new cor command allows you to checkout branches by regex (well, sort of) like this:

Note: I know my “checkout by regex” implementation is not bulletproof but, I’ve been using it for more than a year now and it never failed me.

The “checkout by regex” is a very good example of trying to spot things that can be improved and speed them up using Git aliases.

As already mentioned the fact that gitconfig allows you to write aliases with any bash commands has a lot of interesting potentials. Let’s look at a final example.

The amazing FZF allows you to do a very fast fuzzy search which allows you to pimp your Git aliases:

We basically combined the power of FZF with Git. Pretty cool ah? :)

And all the aliases combined:

Some of you may be wondering why not use some git plugin like oh-my-zsh git plugin instead of creating your own custom aliases. There are multiple reasons I could think of:

Why add a plugin when you can easily do all the stuff the plugin can without it? This is especially true if you alias git to g .

to . The plugin creates global aliases which feels a bit awkward to me. I would rather have all the aliases available only in a Git context.

I think the space after the g makes my commands slightly easier to read.

makes my commands slightly easier to read. When using the plugin you get a lot of aliases that you are either not familiar with or are not part of your workflow which feels like an overkill to me.

Let’s summarize:

Utilizing Git aliases as part of your workflow can dramatically improve your productivity — imagine how many times a day you’re using all these basic commands like status , commit , checkout , commit --amend and many more.

, , , and many more. Use aliases to group multiple commands together. Don’t forget you can even use bash commands.

To speed your Git workflow it’s important to work deliberately, always look for actions you’re performing multiple times a day and try to create useful aliases for them.

If you’re already familiar with Gitconfig and you feel like I’ve missed something or just want to share more cool aliases — let me know :)