World map

 

BM: Baca dalam Bahasa Melayu

World 1: Save Points

HEAD: you are here

You will learn: what HEAD is, and how it moves when you commit.

The problem

Four commits wobble on the timeline: Add README, Add home page, Add purple style and Add about page.

You have four save points. Which one are you standing on right now? Games show a “you are here” dot. Git has one too.

Watch

git log --oneline. The top line, Add about page, has HEAD -> main next to its hash. Terminal output: $ git log --oneline 1d9a185 (HEAD -> main) Add about page 284495e Add purple style e9e6425 Add home page 6d3a9b1 Add README

See HEAD on the top line? HEAD is Git’s “you are here” marker. Right now it sits on your newest commit.

Try it

On the graph, HEAD is the pink marker. Find it.

Tap the commit HEAD points at.

6d3a9b1e9e6425284495e1d9a185

Watch

git branch prints one line: a star, then main. Terminal output: $ git branch * main

HEAD points at a branch: a named line of commits. Yours is called main. git branch lists branches. The * marks the one HEAD points at.

Predict

You make one more commit. Where does HEAD end up?

Pick one answer.

Watch

A new commit dot appears after Add about page. The main tag and the pink HEAD marker both slide onto it.
6d3a9b1e9e6425284495e1d9a185

The new commit lands. main moves onto it, and HEAD rides along with main. That is why you always stay at the front.

You did it!

You can now find HEAD and predict where it goes next.

Go deeper (optional)

Git keeps HEAD in a tiny file, .git/HEAD. Most of the time it says ref: refs/heads/main, which means “HEAD points at main”. In World 2, you will move HEAD onto an old commit. That is called a detached HEAD.