Git branch explained: a name on the graph, not a copy
By Christophe Paka · Facts checked on 7 November 2026
You want to try an idea without breaking the version that works. Someone says make a branch, and you picture Git duplicating your whole project into a second folder. So you hold back, because copies feel heavy and easy to mix up.
That picture keeps people from the one Git habit that costs nothing.
Here is git branch explained in one figure: five commits, two branch names and HEAD. Once you see that a branch is only a label on a commit, creating, switching, renaming and deleting branches stop being scary.

Use this diagram on your site
Free to share in your blog post, docs, course or slides, as long as the credit link stays. Paste the code below where the figure should go.
How to read this figure
Read the row C1, C2, C3. Each circle is a commit, and each arrow points from a commit back to its parent, the commit it was made on top of. Together they form the commit graph, your history.
See the line split after C3. Two commits were made on top of C3: C4 on the upper line and C5 on the lower line. Two lines of work share the same past.
Find the two names, main and feature. main names C4, and feature names C5. A branch is a name that points to one commit and moves forward with each commit you make on it. No files were copied to make either one.
Spot HEAD on main. HEAD is Git's "you are here" marker. It points to main, so your next commit lands on the upper line and main moves to it. git switch moves HEAD to another branch and updates your files to match.
Look ahead to M. M does not exist yet: Git makes it next, when you merge feature into main. It is a merge commit, with two parents, C4 and C5, and main then moves to M. See fast forward vs three way merge.
Key takeaways
- Give every idea its own branch with git switch -c: it costs nothing, so you try more ideas.
- Run git branch before you commit; the star marks the branch HEAD is on.
- Delete merged branches with git branch -d, and let its refusal warn you about unmerged work.
Try this: create, list, rename and delete a branch
Use any repository with at least one commit on main, with a terminal open in it and git status showing a clean working tree.
- Create a branch and move onto it:
git switch -c idea. - List branches:
git branch. You see main and idea, with a star on idea. - Rename it:
git branch -m idea notes, then make one commit on it, for examplegit commit -am "Add notes"after editing a tracked file. - Go back:
git switch main. - Try to delete it:
git branch -d notes.
Expected result: Git refuses with error: the branch 'notes' is not fully merged, because its commit is on no other branch. That refusal protects your work. Capital git branch -D notes deletes it anyway.
Questions readers ask
How can I rename a local Git branch?
Run git branch -m old new, with the current name, then the name you want. The branch keeps pointing at the same commit; only its name changes.
How do I delete a Git branch locally?
Run git branch -d name. It deletes a branch only when its work is merged; otherwise it refuses. git branch -D name deletes it anyway. If you regret it, git reflog still lists its commits, and git switch -c with a commit ID brings them back.
Should I use git checkout -b or git switch -c?
Both create a branch and move onto it, and git checkout still works. git checkout does two jobs, switching branches and restoring files. git switch and git restore are its clearer halves, so use git switch -c.
Sources: Pro Git: Branches in a Nutshell (git-scm.com); git branch (git-scm.com); git switch (git-scm.com).
This figure is from Git Made Crystal Clear, chapter 4.
The chapter builds the idea step by step, with recipes you can follow, a Try it to check yourself, and every source.
Get the book


