Topic 10

Branches and Merging

Concept

Maya wants to build a new favorites feature for Pageturn. It'll take her a few days, and halfway through, the code will be a mess of unfinished work. She can't do that in the same code readers are using right now — she'd break the live site while she experiments.

The answer is a branch: a separate line of work, split off from the shared code, where Maya can make commits freely without touching what everyone else relies on. When the feature is finished and working, merging folds her branch back into the shared version. Branching and merging are how a whole team works on one project at once without stepping on each other.

A branch splits off, work happens safely, then merges back into main
mainthe shared code
New branchMaya's own line
Commitsthe feature takes shape
Mergefolded back into main

The main version

Every repo has one version that counts as the real, current Pageturn — the shared code everyone builds on and the version that gets deployed to readers. By long convention it's called main. Keeping main healthy and working is the team's shared priority, because main is what ships.

You don't want half-finished experiments landing in main, because anything there is supposed to be solid. So the trick is to do your messy, in-progress work somewhere else, and only bring it into main once it's ready.

A branch: working off to the side

A branch is exactly that "somewhere else" — a separate line of work that starts from the same point as main and then goes its own way. Think of it like writing your section in your own draft document instead of typing straight into the shared manuscript everyone is reading.

On her branch, Maya can commit as often as she likes, break things, fix them, and try ideas — and none of it touches main or the other developers. The live site and everyone else's work carry on untouched while her feature quietly takes shape.

Many branches at once

Branches aren't just for one person. The other developers each have their own, working on their own features in parallel. Five people can be changing Pageturn at the same time, each on a separate branch, none of them colliding — the exact problem version control set out to solve.

This is why branching is the everyday rhythm of a real team: almost no one works directly on main. You branch off, do your work, and bring it back.

Merging: folding it back in

When Maya's favorites feature is finished and working, it has to rejoin the real Pageturn. Merging is that step — it takes the changes from her branch and folds them into main, so now everyone's copy includes her feature.

Most of the time the system merges the changes cleanly on its own. But if two branches changed the very same lines, it can't guess who's right, so it stops and asks a human to resolve the conflict — a normal part of the work, not a failure. Branching and merging is the core daily loop you'll practice in Git for Beginners, and it's the foundation of the pull request, which is next.

Common Confusions
  • "A branch is a separate project." A branch is a line of work inside the same repo, split off from main. It shares the project's history and is meant to rejoin main, not stand apart as its own thing.
  • "Merging always happens automatically and never conflicts." Usually it's automatic, but when two branches change the same lines, the system stops and asks a person to sort out the conflict.
  • "You should just work directly on main." Almost no team does — unfinished work on main breaks the version everyone ships. You branch off, then merge back when it's ready.
  • "A branch is a backup of the code." A branch isn't a safety copy; it's a place to make new changes in parallel, kept isolated from main until those changes are ready.
Why It Matters
  • Branching and merging is the daily workflow of every team that uses Git — learn this and you understand how real teams actually move.
  • It's what finally solves the collision problem from the last topic: many people change the same project at once without overwriting each other.
  • The branch is the thing a pull request proposes to merge — so this topic is the direct setup for the next one.
  • You'll do branching and merging by hand constantly in Git for Beginners and Git, GitHub & GitHub Actions; meeting the idea now makes those courses click.

Knowledge Check

What is a branch for?

  • Working on a change without touching the shared main code
  • Permanently splitting the project into two completely separate products
  • Keeping a backup copy in case the main code is ever lost
  • Storing the app's data while it runs for real users

What does merging do?

  • Folds a finished branch's changes back into the main code
  • Deletes the main version and starts the whole project over from scratch
  • Copies the running app onto a second server
  • Locks the file so no one else can edit it

Why do developers do their work on branches instead of directly on main?

  • So unfinished work doesn't break the version everyone ships from
  • Because only one branch is allowed to exist at any time
  • Because the main version simply cannot be changed once it is created
  • So the app will load faster for the people using it

You got correct