BM: Baca dalam Bahasa Melayu
World 3: Parallel Universes
Make and switch branches
You will learn: how to hop onto a branch, and make one in one step.
The problem
You made a dark-mode note. But the star is still on main. How do you hop over?
Watch
git switch dark-mode moves HEAD onto that note. Your new commits now go on dark-mode. main stays safe.
Try it
Hop onto the dark-mode branch.
Hint
Typegit switch dark-mode, then press Enter.Watch
In a hurry? git switch -c about makes a new note and hops on. Two steps in one.
Try it
Two branches grew apart. Think of them as two universes. Hop into each one and watch your files.
Tap a lane, or pick a universe below. Watch the files change.
Your folder in the main universe
- README.md
- index.html
- style.css
index.html
<h1>My Diary</h1> <p>Day 1: I learned Git.</p> <p>Day 2: I learned branches.</p>
Hint
Tap the other lane, or theabout button.Predict
You are on about. You switch to main. What happens to about.html in your folder?
Pick one answer.
Try it
Make a branch called contact and hop onto it, with one command.
Hint
switch hops. -c creates first.You did it!
You can now make branches and hop between them.
Go deeper (optional)
git switch - hops back to the branch you were on. Changed files but didn’t commit? Git carries them along when it is safe. If a change would get lost, Git stops and tells you. Lesson 9 shows the fix: stash.
Bahasa Melayu
Anda dah buat nota dark-mode. Tapi bintang masih di main. Macam mana nak pindah ke sana?
git switch dark-mode alihkan HEAD ke nota itu. Commit baru anda kini masuk ke dark-mode. main kekal selamat.
Pindah ke branch dark-mode.
git switch dark-mode, kemudian tekan Enter.Nak cepat? git switch -c about buat nota baru dan terus pindah ke situ. Dua langkah jadi satu.
Dua branch dah berpisah jalan. Anggap ia dua alam. Masuk ke setiap satu dan tengok fail anda.
about.Anda di about. Anda tukar ke main. Apa jadi pada about.html dalam folder anda?
Buat branch bernama contact dan pindah ke situ, dengan satu arahan.
switch untuk pindah. -c untuk buat dulu.Kini anda boleh buat branch dan lompat antara branch.
You finished this before. Practice is always welcome!
Official docs: git switch · git branch
You've learned for 25 minutes. A short break helps your brain.
Sprint done! Great focus. Stretch for a minute?