Git branches: work on a copy of the line, then merge it back
Learn why teams use branches, how to make, switch and merge one, and what a clean merge looks like, so your test changes never break the main line of work.
L1–L4 are part of the Pro pass
L0 Explain simply
Analogy: a railway siding. Trains run on the main line. A siding lets you park a train and work on it without blocking the main line. When the train is ready, it joins the main line again.
The main line keeps running while you work.
Tom, a tester at Daily List, a to-do list app, uses a siding for his new checks.
What it is: Git records snapshots of tracked project files and available commit history, with who saved each version and when. It runs on your own computer and works without the internet. GitHub is a different thing: a website that stores Git projects so a team can share them. A branch is one slice of Git. It is a separate line of saved versions inside the same project, so you can try changes without touching the main line.
Why it matters: A tester changes files all day, such as new checks and fixed data. If every change goes straight onto the shared line, one slip breaks everyone's work, and Leo cannot tell a good check from a half-written one. A branch gives Tom a safe place to try changes first. He joins them to the main line only when they work.
PLAIN WORDS · 2 in this section
- snapshots
- records of how things stood at one moment
- github
- a web site that hosts code and runs checks
PICTURE IT
The picture is the one the lesson above opens with. The table below shows how each part of it matches the software.
THE REAL JOB A railway siding off the main line.
- Branch
- Commit
- Merge
HOW THE PICTURE MAPS
| In the picture | In the software |
|---|---|
| The main line | main |
| The siding | A branch |
| Moving a train to the siding | Switching branches |
| Rejoining the main line | A merge |
WHERE THIS PICTURE STOPS
- A siding is fixed, but a branch is a label.
- Trains block the main line, but branches never do.
- Only one train fits, but many branches can exist.
HOOK
Work on the siding.
TELL A FRIEND
A siding: work apart, then rejoin.
OFTEN MIXED UP WITH Git from zero: install, first repository, add, commit and log. That topic saves commits. This one puts them on a separate branch and joins them back.
Sources & standards — 3 sources
- Market practice
Git git-branch manual (2.51.0) ↗ — Git project · Git 2.51.0 — DESCRIPTION and -d: branch references, upstream/HEAD reachability and deletion conditions.
Selected publisher sections read for Testing Tools audit. Git 2.51.0. This is not live service testing or a full-publication certification.
- Market practice
Git git-switch manual (2.51.0) ↗ — Git project · Git 2.51.0 — DESCRIPTION and options: working tree changes, -c and preserving compatible local changes.
Selected publisher sections read for Testing Tools audit. Git 2.51.0. This is not live service testing or a full-publication certification.
- Market practice
Git git-merge manual (2.51.0) ↗ — Git project · Git 2.51.0 — DESCRIPTION, HOW CONFLICTS ARE PRESENTED, HOW TO RESOLVE CONFLICTS, --abort: ancestry, incompatible changes, markers and reconstruction warning.
Selected publisher sections read for Testing Tools audit. Git 2.51.0. This is not live service testing or a full-publication certification.
PRACTISE AND KEEP
Sources for this topic — 3 sources
- Market practice
Git git-branch manual (2.51.0) ↗ — Git project · Git 2.51.0 — DESCRIPTION and -d: branch references, upstream/HEAD reachability and deletion conditions.
Selected publisher sections read for Testing Tools audit. Git 2.51.0. This is not live service testing or a full-publication certification.
- Market practice
Git git-switch manual (2.51.0) ↗ — Git project · Git 2.51.0 — DESCRIPTION and options: working tree changes, -c and preserving compatible local changes.
Selected publisher sections read for Testing Tools audit. Git 2.51.0. This is not live service testing or a full-publication certification.
- Market practice
Git git-merge manual (2.51.0) ↗ — Git project · Git 2.51.0 — DESCRIPTION, HOW CONFLICTS ARE PRESENTED, HOW TO RESOLVE CONFLICTS, --abort: ancestry, incompatible changes, markers and reconstruction warning.
Selected publisher sections read for Testing Tools audit. Git 2.51.0. This is not live service testing or a full-publication certification.
Deepest material on this page: L4 — Standards & sources. Where a topic stops short of implementation depth, that is a deliberate coverage decision, not an oversight — see coverage.