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.
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.
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.
You make a branch called experiment. How much disk space does git use for it?
A branch is a name for a commit, stored as a tiny file containing a hash. Files only cost space when you commit new contents, and even then git stores each unique piece of content just once.
git merge says 'Fast-forward'. What happened?
Fast-forward means one branch was already an ancestor of the other. There was nothing to combine, so git moved the label. No merge commit is made unless you ask with --no-ff.
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.
Sources
Missions and quizzes above earn their own XP. This marks the lesson done.