Ijah’s photo album at Mr. Harun’s studio: a photo is a commit, a ribbon a branch, the red ribbon HEAD. Tie ribbons, switch, merge by fast-forward or with two…
Why it matters
git is used every day, yet many people fear branch and merge because they never see what moves. Once you see that a branch is only a name on one commit, HEAD only a marker of where you are, and a merge makes a commit with two parents, the commands stop feeling like magic.
The key idea
A commit is a photo, a branch only a ribbon that slides
Common mistakes
Thinking a branch copies the folder A branch is only a name pointing at one commit, a small file in .git/refs/heads/ holding its number. Making and dropping branches is nearly free, so use them freely.
A commit "lost" after checkout The commit is not lost, HEAD moved. It stays on its branch: git switch back to it. git reflog records everywhere HEAD has been.
Fearing merges or a detached HEAD A clashing merge stops and waits: choose the content, git add, then git commit, or back out with git merge --abort. A detached HEAD means HEAD points at a commit, not a branch: make a branch there if you want to keep it.
Try it in this playground
Tie a new ribbon with git branch No photo is copied: a ribbon is only a name pointing at one photo.
Shoot without git switch first A commit moves the ribbon HEAD is on. The new ribbon stays behind.
A merge that only slides a ribbon A fast-forward: no merge photo, the ribbon slides ahead.
A merge photo with two parents Two lines that parted meet again in one photo.