Git in Plain English

July 18, 2022

dev
git

Like many other tools, Git uses its own vocabulary as an interface. The plethora of commands we can pass in the terminal allows us to fine-grain our requests and change branches, checkout commits, or change remote-tracking branches as we want.

However, the multitude of options we have in the palm of our hands makes it somehow very hard to memorize and understand exactly what each command does.

This is a non-exhaustive list of a direct translation of Git commands to plain English.

1. HEAD

HEAD is the symbolic name for the commit we're currently checked out at.

git checkout main

Means: checkout to the commit to the one indicated by the branch main.

2. ^ sign

^ sign basically indicates - one commit earlier (or parent commit).

So when you type

git checkout HEAD^

we simply say - checkout to the parent commit of a current HEAD. We can add many ^ signs to go back few commits at a time:

git checkout HEAD^^^

"Checkout to the great-grandparent of HEAD"

If a commit has two parents, we can decide which of them we checkout to by adding a number after the ^ sign:

git checkout HEAD^2

"Check out to the second parent"

3. Tilde sign (~)

The ^ sign is quite powerful but that method can quickly get quite tedious. That's why Git introduces the tilde sign (~). When used individually it functions exactly like the ^ sign - it points at the parent commit. However, if we want to go back, say, 6 commits, we can simply type:

git checkout HEAD~6

What's even cooler is that we can mix both signs to fine-grain the time travel:

git checkout~3^2

Means: checkout to three commits back and then one more, but use the second parent.