Best Git Aliases

November 08, 2018

Aliases are a way to make your life with git easier. They allow you to make long, complex command line instructions much shorter. You can alias all git commands, but some make more sense than others. Here are some of my favourites:

One Line Logs:

ls = log --pretty=format:"%C(yellow)%h%Cred%d\\ %Creset%s%Cblue\\ [%cn]" --decorate

The standard git log gives a rather verbose, spaced output, that can be difficult to parse quickly if you only wnat to see basic details.

Using this command, you'll be able to only see the essentials of a commit, but it'll be easier to quickly get the information you need.

Newest Branches First

br = branch --sort=-committerdate

This is a simple one; it shows your branches, but ordered by commit date. This means you can see the branches you've worked on recently first, which is great when you just cna't remember the name of the branch you need.

Add Tracked Files

a = add -u

Another short one. Adding every file manually is great when you need fine grained control, but when you just want to add all the files you've worked on, this alias is what you need. It won't add untracked files, so this one is often a big time saver.

Create a New Branch

cob = checkout -b

I almost always use checkout -b to create a branch in git; it's very rare that I want to create a branch without also checking it out. checkout -b isn't exactly a long command, but it helps to be able to cut it down to cob.

Get the Status of a Project

st = status

This one might just be personal to me, but for some reason I regularly mistype status. st is one which helps me out, but if there's something you're regularly mistyping, do yourself a favour and alias it!