Branches: try ideas safely

Play this lesson

Two plans, one game

Kai wants to try lasers that bounce off walls in Hyper Shards. Remy is about to show the game to friends at school tomorrow.

Our code is saved in commits, save points that Git keeps. If Kai commits half-finished lasers tonight and they break the game, Remy's demo crashes. Is there a way to experiment without touching the version that works?

What is a branch?

A branch is a separate line of commits. It starts from the project as it is, and commits on it don't touch any other branch.

Every repo has a main branch, usually called main. Our rule: main always stays playable.

Under the hood, a branch is just a name that points at its newest commit. That's why making one is instant, even for a huge game.

Our studio's branches

Branch pick

Branches
maindevfeature/bouncy-lasersfeature/snail-pest

These are the branches in the Hyper Shards repo. Remy's school demo is tomorrow. Which branch should Remy play from?

  1. main
  2. dev
  3. feature/bouncy-lasers
Show the answer

main

main is the version that always works. dev still has features being tested together, and feature/bouncy-lasers is Kai's half-finished experiment.

Branch commands

In the terminal, the window where you type commands:

git branch lists branches. A star marks the one you're on.
git switch -c feature/bouncy-lasers creates a branch and moves onto it. -c means create.
git switch main moves back to main.

Switching swaps the files in your folder to match that branch. Commit first, or your unsaved changes come along, and Git refuses if they would be overwritten. Older guides use git checkout -b for the same job.

Quick check

Kai is on main and wants to start the bouncy lasers experiment. Which command?

  1. git switch -c feature/bouncy-lasers
  2. git merge feature/bouncy-lasers
  3. git branch -d main
Show the answer

git switch -c feature/bouncy-lasers

git switch -c creates the new branch and moves onto it, so Kai's commits land there and main stays playable.

Merging

When the lasers work, Kai merges: combines one branch's commits into another. First switch to the branch that receives the work:

git switch dev
git merge feature/bouncy-lasers

If dev hasn't changed since the branch started, Git just slides dev forward, called a fast-forward. Otherwise it makes a merge commit that joins the two lines.

Features flow one way: feature branch into dev, then dev into main once everything is tested together.

Check first, undo safely

On GitHub, the team usually merges through a pull request (PR): "here are my changes, please check them before they go in". PRs have their own lesson in this stage.

If a bad change already got merged, git revert a1b2c3d makes a new commit that undoes commit a1b2c3d. The history keeps both, so nothing is hidden.

Finished with a branch? git branch -d feature/bouncy-lasers deletes the name. Its commits stay safe in dev.

Quick check

A change merged into main makes Garden Defense crash. What's the safest fix?

  1. Delete the whole repo and start again
  2. Revert the commit that caused the crash
  3. Leave it and hope players don't notice
Show the answer

Revert the commit that caused the crash

Revert undoes that one change with a new commit. Everything else stays, and the history shows exactly what happened.

Same line, two branches?

Branches let Kai and Remy work at the same time. Usually Git combines their work without any help.

But what if both of them change the very same line of balance.json, on different branches?

Bolt says: Git can't guess which one is right. Next lesson: merge conflicts, and how to fix them calmly.

Fact-checked 9 October 2026