SWE.for vibe coders
Lesson 3 of 411 min

Branches, without the fear

How to try risky changes in a parallel universe — and merge them back only if they work.


You now have save points. Branches are the next unlock: a way to work on something risky without touching the version that already works.

A parallel universe for your code

A branch is a separate line of history. Picture your commits as a timeline. A branch splits off a parallel copy where you can make changes freely. The original timeline (usually called main) stays exactly as it was.

If the experiment works out, you merge it back into main. If it doesn’t, you throw the branch away and main never even knew it happened.

The commands

Create a branch and switch to it in one step:

terminal
$git switch -c redesign-homepage
Switched to a new branch 'redesign-homepage'

Now every commit you make lands on redesign-homepage, not main. Make your changes, commit them as usual. When you want to go back to the safe version:

terminal
$git switch main
Switched to branch 'main'

Your files instantly change back to how main looks. The redesign work isn’t gone — it’s safely on its branch, waiting. Switch back anytime with git switch redesign-homepage.

Check yourself

You're on a branch called 'experiment' and you run git switch main. What happens to the work you did on 'experiment'?

Merging it back

Happy with the branch? Bring it into main. First switch to the branch you want to merge into (main), then merge the other one in:

terminal
$git switch main
Switched to branch 'main'
terminal
$git merge redesign-homepage
Updating a1b2c3d..f4e5d6c
Fast-forward
index.html | 40 ++++++++++++++++++++++++++--------------

Now main contains the redesign. You can delete the branch — it’s served its purpose.

Check yourself

Why is doing risky work on a branch better than doing it directly on main?

Try it for real

In a git project you’ve got lying around:

  1. Run git switch -c my-experiment to branch off.
  2. Change a file and commit it (git add . then git commit -m "Try something").
  3. Run git switch main — watch your change vanish from the files.
  4. Run git switch my-experiment — watch it come back.

Feel that? That’s the safety net. Nothing you do on a branch can hurt main.