What is a branch, physically?
A branch is a name that points at one commit. That is all Git stores for it: a tiny file holding a commit id. main in the bakery repository points at "Add the menu". When you commit on main, Git makes the new commit and moves the main label forward onto it.
Creating a branch therefore copies nothing. git branch summer-menu writes a new label pointing at the same commit as the branch you are on. Both names now lead to the same history. They only separate once you commit on one of them.
The Graph view draws branches exactly like this. Each label sits on a dot, and the filled ◆ marks the branch you are on. Run git branch and the same branch is marked with a *.
git branch
git branch summer-menu
git branch
git log --oneline

summer-menu gets the tart and main stays where it was.What is HEAD?
HEAD is Git's word for "where you are now". Usually it points at a branch name, and that branch points at a commit. When you commit, the branch that HEAD names is the one that moves.
That is why you switch before you commit. If you meant to try the summer menu on its own branch but forgot to switch, the commit lands on main. git status always prints On branch ... on its first line; reading that line before every commit is a cheap habit that prevents this.
How do you create and switch branches?
git switch <name> moves HEAD to an existing branch and updates your files to match that branch's latest commit. git switch -c <name> creates the branch and switches to it in one step. That pairing covers most daily work.
Older tutorials and many AI answers use git checkout <name> and git checkout -b <name> for the same jobs. They still work. checkout also restores files and moves to old commits, which made it easy to misuse, so Git added switch and restore to split those jobs apart.
Watch the editor tab while you switch. index.html changes in front of you: the tart line appears on summer-menu and disappears on main. Git rewrites tracked files to match the branch, and leaves untracked files alone.
git switch -c summer-menu
echo "<p>Strawberry tart, 3.20</p>" >> index.html
git commit -am "Add strawberry tart"
git switch main
cat index.html
git switch summer-menu
cat index.htmlWhat happens to uncommitted changes when you switch?
If you edited a file and the branch you switch to has the same version of that file, Git carries your edit along. If the other branch has a different version, Git refuses with "Your local changes would be overwritten by checkout" and switches nothing.
The refusal protects your work. The fix is to commit the change on the branch where it belongs, or put it aside with git stash and bring it back later with git stash pop.
A clean git status before switching avoids the question entirely. It also keeps each branch's commits about one idea.
When should you make a branch?
Make one for any change you might want to throw away, or that will take more than one sitting: a new menu layout, a redesigned header, a bird sightings map. main stays the version that works, and once the site is published from it, every commit there goes live.
Name branches after the change, using lowercase words and dashes: summer-menu, fix-footer-link, add-walk-calendar. Spaces are not allowed, and names that describe the work make git branch readable a month later.
Small solo fixes, such as one typo on your own profile page, can go straight onto main. Teams usually make a branch for everything, because changes reach main through pull requests.
How do you rename and delete branches?
git branch -m old-name new-name renames a branch. Run git branch -m new-name on its own to rename the branch you are on. Commits are untouched; only the label changes.
git branch -d name deletes a branch whose commits are already part of the branch you are on. If they are not, Git refuses with "not fully merged", which is a warning worth reading: those commits would become hard to find. git branch -D name deletes anyway.
You cannot delete the branch you are on. Switch to main first.
git branch summer-menu
git branch -m summer-menu summer-specials
git branch -d summer-specials
git branchWhat is a detached HEAD?
If you switch to a commit id instead of a branch, for example git switch --detach 3f9a2c1 or the older git checkout 3f9a2c1, HEAD points straight at a commit with no branch name in between. Git calls this detached HEAD.
It is fine for looking around an old version. The risk comes if you commit there: no branch moves to hold the new commit, so once you switch away it is hard to find. If you want to keep work you did while detached, run git switch -c some-name before leaving, and the commits get a branch.
The Graph shows a detached HEAD as a ◆ with no branch label next to it.
What do branches look like on GitHub and for teams?
Branches you create live only in your repository until you push them. On GitHub each pushed branch appears in the branch menu, and a pull request is a request to merge one of them into main.
For the bird club site, three volunteers might each work on a branch: one on the walk calendar, one on a photo gallery, one fixing the footer. None of them can break the live site, because the site is built from main, and each branch reaches main only after someone reviews it.
On your own profile page the same idea gives you a safety net. A redesign branch can stay half-finished for weeks while main keeps the working page you can publish at any time.
How do you see every branch at once?
git branch lists local branches with * on the current one. git log --oneline --all lists commits from every branch, newest first, with labels in brackets showing which branch points where.
The Graph view is the visual version of --all. After the task you should see main on "Add the menu" and summer-menu one dot further, on "Add strawberry tart".
git branch summer-menu
git log --oneline --allField notes
- A branch is a name that points at one commit.
HEADmarks where you are now, usually on a branch.git switch -c <name>creates a branch and moves you onto it.- Commits made on a branch leave
mainuntouched until you merge.
Easy to get wrong
git branch creates the label but leaves you where you were. The commit lands on main.
Branch names cannot contain spaces. Git reads the second word as a separate argument.
Lowercase -d refuses to delete unmerged work. Capital -D deletes it silently.
Questions people ask
Does a branch copy my files?
No. Git stores the branch as a pointer to a commit. Your folder shows one branch at a time, and switching rewrites the tracked files.
What is the difference between git switch and git checkout?
For branches they do the same thing. switch only moves between branches, which makes it harder to misuse. checkout also restores files and visits old commits.
Why is my default branch called master?
Older Git versions used master. Newer ones and GitHub use main. git branch -m master main renames it.
How many branches can I have?
As many as you like. They cost almost nothing. Delete them once merged so git branch stays readable.