Fix the bug: forgot to switch branches
Every lesson so far asked you to type a script from scratch. Real work is
more often the opposite: someone else's script is already there, and it's
broken. This one doesn't throw an error or print anything scary - it runs
clean, top to bottom, and looks like it worked. That's what makes it worth
knowing: a wrong branch doesn't crash, it just quietly commits your work in
the wrong place.
The script below is supposed to create a branch called feature and commit
feature.txt there, keeping main untouched. Run it, then check where the
commit actually landed - git branch --show-current or git log --oneline
will tell you the truth. git branch feature only creates the branch. It
doesn't move you onto it - you're still standing on whatever branch you were
already on when the next commands run.
Your task: fix the script so the commit for feature.txt lands on
feature, not main. When you're done, main should still have only its
original commit.
You'll practice:
Noticing that git branch <name> creates a branch without switching to it
Reaching for git checkout -b <name> when you want both in one step
Show a hint
Show solution
Previous