Moving around in Git by specifying commit hashes can get a bit tedious. In the real world you may not may a nice commit tree visualization next to your terminal, so you'll have to use gitk or git log to see hashes.

The hashes are the ids used by git to identify each commit. Hashes are usually a lot longer in the real Git world as well. For instance, the hash could be: 'fed2da64c0efc5293610bdd892f82a58e8cbc5d8'.

The upside is that Git is smart about hashes. It only requires you to specify enough characters of the hash until it uniquely identifies the commit. So I can type fed2 instead of the long string above.

With relative refs, you can start somewhere memorable (like the branch bugFix or HEAD) and work from there. Relative commits are powerful, here are two simple ones here:


Command Description
^ Move upwards one commit at a time
~n Move upwards a number of times

Before moving

Git before checkout master^


Let's look at the Caret (^) operator. Each time you append that to a ref name, you are telling Git to find the parent of the specified commit.

So saying master^ is equivalent to "the first parent of master".

You can also reference HEAD as a relative ref. For instance, moving to the grandparent of the current position:
git checkout HEAD^
git checkout HEAD^

or simply
git checkout HEAD^^

After moving

Git after checkout master^


git checkout master^
Easy! We can travel backwards in time with ^

To complete this level, check out the parent commit of bugFix. This will detach HEAD.