Curious Pandas

Branches are just names

A branch isn't a copy of your project. It's a sticky note pointing at one commit. Make one, change it, and merge it back.

12 min+30 XP for finishing

People picture a branch as a whole separate copy of the project. It isn’t. A branch is a name attached to one commit: a tiny file holding a hash. Making a branch costs nothing and copies nothing, which is why git users make them constantly.

Every commit also remembers its parent, the commit that came before it. So a branch name plus the parent links gives you a whole history: start at the commit the name points to and follow the parents back.

When you commit on a branch, git makes the new commit and moves that branch’s name forward to it. The other branches don’t move. That’s the whole trick.

Branch, change, merge

You start with one commit on main. Make a branch, commit on it, then go back to main and watch your change vanish from the file. It isn’t lost; main simply points at an older snapshot. Then merge.

A branch called ideareal git hashes
Working tree
    Staging area
      Last commit
        Commit graph

        No commits yet.

        Fast-forward vs. a real merge

        In this mission, main didn’t move while you were away. Merging only had to slide the main label forward to where idea was. Git calls this a fast-forward, and it creates no new commit.

        If main had moved, both branches would hold work the other lacks. Then git does a three-way merge. It compares both branch tips with their last common ancestor, combines the changes, and records a merge commit with two parents. Try it in the playground: commit on both branches before you merge.

        Check yourself+10 XP

        You make a branch called experiment. How much disk space does git use for it?

        Check yourself+10 XP

        git merge says 'Fast-forward'. What happened?

        Do it for real · your machine+50 XP bonus

        Everything above ran in your browser. Now do it on a real cluster withthe tilt platform. You need Docker, kind and Tilt, about 15 GB of free disk and 8 GB of spare RAM. Setup guide · Can my machine run it?

        git switch -c idea
        echo "bamboo can grow 90cm in a day" >> notes.md
        git commit -am "add a fact"
        git switch main
        git merge idea
        git log --oneline --graph --all

        --graph --all draws the same picture as the playground, in text.

        Self-reported. We can't see your machine, and we don't want to. This is a bonus, never required.

        Sources

        Finished reading?

        Missions and quizzes above earn their own XP. This marks the lesson done.