Git tip: aliases

The title is a little bit misleading, because this post is going to cover both a Git and a Bash tip. But this is my blog, so I title my posts the way I want.

Please, bring on some tips!

This is a tiny little trick that may be useful only if you ask Git to fulfil your wishes using the command line. Which you should probably be doing at this point, if you want to call yourself a real developer.

Git commands are totally long and totally hard to remember. True. But what if they could be shortened?

Well, in a way, git commands can be shortened. Or at least, adapted to your personal preferences, thanks to aliases.

Aliases can be global or specific to a repository. For example, if you are bored of typing:

You can create a “local” alias:

And from that moment on, you can just do this:

And voilà.

If you want to apply the alias to all your repos:

And voilà again.

My favorite? This one:

Cool, but what about the bash tip?

Yep, I have one of those as well.

bash (the only true Unix shell) allows the creation of shortcuts to certain commands, called alias. For example, if you find yourself typing a thousand times a day the following command:

Wouldn’t it be neat to be able to just type the following?

Well, that’s easy to do in just to steps. First, edit the bash configuration:

Now add the following alias to that file:

Save and exit, and force bash to refresh:

(Note the space between the first dot and the curly-thingy-that-we-use-in-Spanish-on-top-of-the-letter-n-to-make-it-sound-funny)

Now, when you want to checkout a branch, just do:

Ain’t that neat?

Leave a Reply

Your email address will not be published. Required fields are marked *