AI Learning Hub › Learn AI › Self-Paced Courses › GitHub Without the Jargon › Why Branches Exist
Module 4 ยท Beginner
Why Branches Exist
Create a branch, commit on it, switch between two branches to see different file contents, and compare them before combining anything.
By the end
- Explain why a branch can be useful
- Create a branch from the current default branch
- Recognize which branch GitHub is showing
- Make a commit that exists on one branch but not another
- Switch between two branches and observe different file contents
- Compare the branches before combining them
- Explain why creating a branch does not duplicate the whole project into another repository
What if you want to make a change without changing main yet?
Module 3 committed directly to main, and that was the right call for what it was teaching: it made the mechanics visible with nothing else in the way. Edit, review, describe, commit, history — five steps, no distractions.
But look at what happened at the end. The moment the button was clicked, the new Status section was the project. Anyone opening that repository would see it immediately, because main is what GitHub shows first.
Direct-to-main gave us no space between “record the change” and “change the default branch.”
For a disposable practice file that does not matter. For anything with a reader, a colleague, or a deadline attached, that missing space is the whole problem. This module is about creating it.
Three words to learn
Branch
A named line of work in a repository where changes can develop separately from another branch.
Branching
Creating a new branch from an existing point in repository history so work can continue separately.
Compare view
A GitHub view that shows differences between two branches, commits, or other versions of a repository.
Beginner versions, and a longer withheld list than usual. Not needed yet: base branch, head branch, merge base, topic branch, feature branch, checkout, HEAD, upstream, rebase, merge, and pull request. Two of those — base and compare — appear on screen in this module as labels on a form, and you can read them as “starting point” and “the thing being measured against it” without learning them as terms.
Note also that main is a name, not a concept. It is what this repository’s default branch happens to be called, and Module 2 already met a GitHub repository whose default branch is called gh-pages instead.
A branch is not a second repository
The tempting shortcut here is “a branch is a copy of the project.” Resist it. It feels helpful for about ten minutes and then quietly causes trouble, because it makes people expect two of everything — two repositories, two histories, two sets of files to keep in step.
What actually happens:
- a new branch begins from an existing point in the repository’s history;
- at the moment it is created, it may show the same files and content as the branch it came from; and
- after new commits are recorded on one branch, the branches can show different versions.
It is the same repository holding different lines of work.
One repository, one place, one address. What changes is which recorded line of work you are looking at.
Start from what we already have
The practice repository from Module 3, unchanged since that commit:
- Repository
github-without-the-jargon-practice, private- Default branch
main- Branches
- 1
- Files
README.md- Commits on
main - 2
- Latest commit
Add status section to README
The README currently ends here:
## Status
Current status: Ready for review.
This is the point from which the new branch will begin.
Give the next change somewhere else to live
Branches are made from the same control Module 2 taught you to read: the branch selector. Opening it on main shows the panel from Module 2, with one field now doing double duty — Find or create a branch…
Typing a name that does not exist turns the panel into an offer. With review-note typed, the observed interface showed a single option:
Create branch review-note from main
Read that line before clicking it. It names the branch being created and the branch it starts from. If the second name is not what you expect, the field to fix is the branch you are currently on, not the one you are typing.
At first, there may be nothing to compare
After creating the branch, GitHub switched to it — and almost nothing looked different. The selector read review-note, the count read 2 Branches, and the README was identical, down to the same latest commit. A new line appeared above the file list:
This branch is up to date with main.
That is the correct and slightly anticlimactic truth about a new branch. The branch exists before it becomes different.
Creating the branch did not change the file yet. It created another place for future commits to go. If you were expecting something dramatic, that expectation is the “copy of the project” idea trying to reassert itself.
Now change only the branch
With review-note selected, the editing workflow is exactly the one Module 3 taught — open README.md, use the pencil, type, Preview, Commit changes… The only new thing to watch is which branch the page says you are on. In the observed interface it appeared three times: beside the file name at the top, in the sidebar selector, and inside the commit dialog itself.
The addition was three lines at the end of the file:
## Review note
This change is on a branch for review.
Everything else was left alone. Preview with Show diff confirmed it: the title, the description, and the whole Status section were unmarked; only the new heading and its sentence were flagged as changed.
The commit message was Add review note, with the extended description left empty.
The question that is new in this module. Module 3 asked what changed? before committing. That still matters. But on a repository with more than one branch there is a second question, and it is the one that catches people out:
Which branch will receive the commit?
The commit dialog answers it in plain words — the first option read Commit directly to the review-note branch, not main. Read that line every time. It is the difference between a proposal and a change.
Same repository. Different visible version.
Here is the whole point of the module, in two observations taken a minute apart in the same repository.
On main
The README ends here:
## StatusCurrent status: Ready for review.
2 commits. Latest: Add status section to README. No Review note anywhere.
On review-note
The README continues:
## Review noteThis change is on a branch for review.
3 commits. Latest: Add review note. GitHub reports it is 1 commit ahead of main.
Switching the selector back and forth makes the Review note section appear and disappear. Nothing is being created or destroyed as you do it; two recorded versions exist at once, and the selector decides which one is on screen. Switching branches changes which recorded version GitHub shows you, without copying you into another repository.
Three verbs, three different effects
Module 2 sorted the branch selector into the inspection column, on the grounds that choosing an existing branch changes what GitHub shows without modifying anything. You can now see why that was right, and where its limit is. Creating a branch changes repository structure, switching branches changes your view, and committing changes branch history.
Three different actions, easy to blur together because they all involve the same small control in the corner of the page. Creating and committing leave a record. Switching leaves nothing behind at all.
See the difference without combining it
GitHub has a Compare view, reached by adding /compare to a repository’s address. It sets two versions side by side and reports what separates them.
Comparing our two branches, the observed view showed:
- The two sides
- base: main and compare: review-note. GitHub’s documentation describes these as the starting point and the endpoint.
- A verdict
- “Able to merge. These branches can be automatically merged.”
- The scale of the difference
- 1 commit, 1 file changed, 1 contributor.
- The difference itself
- “Showing 1 changed file with 4 additions and 0 deletions.”
And the diff, in the same form Module 3 introduced:
@@ -5,3 +5,7 @@
## Status
Current status: Ready for review.
+
+## Review note
+
+This change is on a branch for review.
Four lines added, nothing removed, one file touched. That matches what we did, which is the point of looking.
Observed on GitHub
Verified: 21 September 2026.
This is the disposable private practice repository from Module 3, and the screenshot shows its two branches being compared. No pull request had been created at this point, and none was created for this module.
GitHub’s labels and layout may change. The green Create pull request button is visible because it is genuinely there on this screen — we are not using it yet. It is Module 5’s subject, and clicking it is a separate, deliberate act.
Compare does not merge
Worth stating flatly, because the page puts a green button next to the thing you came to read.
Opening Compare:
- does not change
main; - does not merge the branches; and
- does not create a pull request by itself, unless you explicitly take that action.
Even the phrase Able to merge is a statement about what could happen, not a report of what has. GitHub is telling you the two versions do not conflict, so that you know a combination is possible if you decide you want one. Comparison lets you inspect the difference while the branches remain separate.
The useful gap
So why not keep committing to main?
Sometimes you should. For the disposable edit in Module 3, direct-to-main kept the lesson simple and cost nothing. Plenty of small personal repositories run that way forever, quite reasonably.
But a separate branch creates a gap between two things that direct-to-main welds together:
I recorded the change
The work exists, with a message and a history entry.
The default branch contains the change
What everyone sees first now includes it.
That gap is where more work, comparison, testing, discussion, and review can happen. None of it is possible if the two events are the same event.
A branch gives a proposed change somewhere to exist before it becomes part of the default branch.
A branch creates separation, not approval
This is the caveat that keeps the previous section honest.
Putting work on a branch does not mean:
- someone reviewed it;
- it is correct;
- it is safe; or
- it will ever reach
main.
Our review-note branch is called that because of what the text says, not because anyone reviewed anything. It has been read by nobody. It simply exists separately. Separation gives you an opportunity for review without performing the review.
Which is exactly the gap Module 5 fills.
Give the line of work a useful name
A branch name helps people understand what line of work they are looking at, in a list where the only other clue is a date.
Unhelpful
stuff
Says nothing. In a list of five branches, forces you to open it.
Useful
review-note
Names the line of work. You can decide whether it is yours without opening anything.
A useful branch name gives context without requiring you to open every commit.
You will see branch names containing slashes in real projects. Those are conventions particular teams adopt, not rules, and they are not worth learning before you need one.
Which version contains the Review note?
The repository as it now stands:
main
- Status section
- no Review note
review-note
- Status section
- Review note
If GitHub is currently showing main, should the Review note appear? And if you switch to review-note?
One possible answer
On main: no. The commit that added it was recorded on the other branch. main has never contained it.
On review-note: yes. That is where the commit went.
Neither answer involves anything being copied, moved, or lost. The repository contains both lines of work. The selected branch determines which recorded version GitHub is showing.
Which actions create history?
Eight things we did, in order. Which of them altered the repository, and which only looked at it?
A. Open branch selector
B. Switch from main to review-note
C. Create review-note
D. Open README
E. Edit README
F. Commit "Add review note"
G. Switch back to main
H. Open Compare
One possible review
C — Create review-note changes repository structure. There is now a branch that did not exist before, and the branch count went from 1 to 2.
F — Commit Add review note adds new recorded history to review-note. That branch went from 2 commits to 3.
The others inspect, navigate, or prepare a change. A, B, D, G, and H only alter what is on your screen — and H, despite the green button sitting next to it, did nothing to either branch.
E is the interesting one. Typing the edit changes the editor’s working content, and you can see the text on screen — but the new repository history appears when the commit is finalized. That is Module 3’s distinction, holding up under a second set of circumstances.
What problem did the branch solve?
Three accounts of what creating review-note accomplished. Only one is right.
A. It made another complete
GitHub repository.
B. It let the new commit exist
without adding it to main.
C. It prevented the change from
ever being wrong.
One possible answer
B. That is the entire job a branch did here: the commit is recorded, findable, and real, and main does not contain it.
A is wrong, and it is the most common wrong answer. There is still exactly one repository, at one address, with one set of settings and one issue tracker. The branch count went from 1 to 2; the repository count stayed at 1.
C is wrong, and it is the more dangerous mistake, because it sounds like caution. A branch has no opinion about whether your change is any good. Our branch-only commit could have contained a serious error and GitHub would have recorded it just as willingly. Branches separate lines of work without duplicating the repository or guaranteeing quality.
What to notice
A branch gives us a state we did not have at the end of Module 3.
main
The version GitHub shows first remains unchanged.
review-note
The proposed new work exists here.
Compare
We can inspect what separates them.
The change is recorded, but it has not become part of main.
Hold that sentence. It describes a situation with no equivalent in ordinary document editing, and it is the situation every collaborative workflow on GitHub is built on top of.
Before you continue
You are ready for Module 5 if you can:
- explain why branches exist;
- explain why a branch is not another repository;
- create a branch from the current default branch;
- identify which branch GitHub is showing;
- explain why two branches can initially look identical;
- make a commit on one branch without adding it to another;
- switch branches and observe different file contents;
- use Compare to inspect the difference; and
- explain why separation is not the same thing as review.