BM: Baca dalam Bahasa Melayu
World 3: Parallel Universes
A branch is a sticky note
You will learn: what a branch really is, and how to make one.
The problem
You want to try a dark theme for your diary. But main must keep working. Where can you play safely?
Watch
A branch: A storyline of commits. Each branch has a name, like main. is a sticky note on a commit. git branch dark-mode sticks a new note here. You stay where you are.
Try it
Make a branch called dark-mode.
Hint
Typegit branch dark-mode, then press Enter.Watch
git branch with no name lists your notes. The star marks the one you are on.
Try it
Notes can go on old commits too. Stick a note called idea on “Add day 1 page”.
Tap a commit. Then stick a new branch on it.
Hint
Tap the middle commit. Then tap “Stick it here”.Predict
You are on main. You make a new commit. Which note moves forward?
Pick one answer.
Check
See? Only main moved. HEAD rides along on main. dark-mode waits on the old commit.
You did it!
You can now make branches and see what they really are.
Go deeper (optional)
git branch -v shows the commit under each note. git branch -m dark-mode night-mode renames one. Branch names can’t have spaces. Teams use - and /, like feature/dark-mode. Why are branches so cheap? Inside Git, a branch is just a name holding one commit id.
Bahasa Melayu
Anda nak cuba tema gelap untuk diari anda. Tapi main mesti terus berfungsi. Di mana anda boleh cuba dengan selamat?
Branch (cabang) ialah nota pelekat pada commit. git branch dark-mode lekatkan nota baru di sini. Anda kekal di tempat sama.
Buat branch bernama dark-mode.
git branch dark-mode, kemudian tekan Enter.git branch tanpa nama senaraikan nota anda. Bintang menanda nota tempat anda berada.
Nota boleh dilekat pada commit lama juga. Lekatkan nota bernama idea pada “Add day 1 page”.
Anda di main. Anda buat commit baru. Nota mana yang bergerak ke depan?
Nampak? Hanya main yang bergerak. HEAD menumpang di atas main. dark-mode tunggu di commit lama.
Kini anda boleh buat branch dan faham apa sebenarnya branch.
You finished this before. Practice is always welcome!
Official docs: git branch · Branches in a nutshell (Pro Git)
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?