Skip to main content
πŸ“œ WAYPOINT LESSON

Branches: Experiment Without Breaking Things

⭐ beginner⏳ 16 min readπŸ“ Lesson 47 of 143

Branches let you try ideas in a parallel sandbox and merge them back when they work β€” how teams (and careful solo developers) work.

A branch is a parallel line of history. The default branch β€” usually main β€” is the stable version. A new branch is a safe sandbox: experiment freely; main never notices until you merge.

The workflow

git branch about-page        # create a branch named about-page
git switch about-page        # move onto it (git switch -c about-page = both steps)
...edit files, add, commit...
git switch main              # back to the stable line
git merge about-page         # bring the branch's work into main

While on about-page, commits land on that branch. main stays untouched β€” that is the entire point.

Resolving a basic conflict

A conflict happens when two branches change the same lines. Git marks the collision in the file itself:

<<<<<<< HEAD
Welcome to my site
=======
Welcome β€” come on in
>>>>>>> about-page

You resolve it by editing the file to the version you want (or a blend), removing the <<<<<<< markers, then git add + git commit. Conflicts are not errors β€” they are Git asking you to make a decision it refuses to guess.

Real habits

  • One branch per idea or feature; short-lived branches merge cleanly
  • Never commit straight to main in a team repo β€” branch, even alone, for practice
  • git branch lists branches; git log --oneline --all shows every line

What you learned

  • git branch/git switch create and enter sandboxes
  • Merge brings completed work back into main
  • Conflicts are decisions, not failures β€” edit, add, commit

Next: taking your repositories online β€” GitHub.

⚑ Now practice

Ready to Code
Branches: Experiment Without Breaking Things β€” PracticeHands-on practice for β€œBranches: Experiment Without Breaking Things”: apply what you just learned in git-branches.
1 challenge Β· Β· ~10 min