Using Git from the command line can be both liberating and daunting. Once you appreciate the power that some of the more verbose commands give you, it is easy to get overwhelmed if you’re not super comfortable on the command line. When you start digging into the formatting functionality of “log” you’ll quickly find yourself looking for a better way to reuse several log formatting options.
For example, one of the more common log formats I use:
I’m pretty sure I found this somewhere on Stack Overflow, and while it makes reading the log nicer, who wants to type that in every time?
Oh Aliases, Yer the Best!
For the log example above, I configured an alias of “lg” that aliases the command with all the formatting so I don’t have to type it every time. Now, whenever I want that specific log format, I just type in “git lg” and blamo, a pretty log for me to look at.
Setting up an alias couldn’t be easier. For example, to create an alias of “co” that aliases the checkout command you’d type the following into your shell:
And you have an alias; Not terribly complicated. Using it is even simpler, just type in “git co” rather than “git checkout” and you’re good to go.
There’s a rub though; for long commands that have ticks and quotes and such, I find that I mess up the syntax creating aliases like this more often than not. I find this irritating because I’m impatient and lazy and I don’t like fighting to get this type of stuff to work.
So I cheat…
Whenever I need to edit my config file I just edit it directly from my C:\Users\yournamehere directory and in the case of aliases, edit the [alias] section. Not hard, and personally I’d rather edit it this way. Powershell is sweet, but a text editor it is not.
To get you started I’ve created a gist of a few commands that I use frequently. Start with these, make your own, and search for other aliases to make your command line Git workflow just that much better.