Branches are the feature that makes Git feel fundamentally different from copying a folder. They let you work on something experimental or unfinished without touching the code everyone else relies on, and because of how Git stores history, creating one costs almost nothing.
What a branch actually is
A branch is not a copy of your files. It's a small, movable pointer - a label - pointing at a specific commit. When you create a new branch, Git doesn't duplicate anything; it just writes a few bytes recording "this name points to that commit." When you make a new commit while on a branch, Git moves that pointer forward to the new commit automatically. This is exactly why branching in Git is near-instant, even on huge repositories, while it was often slow and discouraged in older version control systems.
HEAD: where you are right now
HEAD is Git's pointer to whichever commit you currently have checked out - in the normal case, it points at a branch, which itself points at a commit. Switching branches moves HEAD to point somewhere else, and Git updates your working directory's files to match whatever that branch points to.
Creating and switching branches
git branch <name> creates a new branch pointer at your current commit, without switching to it. git switch <name> (or the older, more overloaded git checkout <name>) moves HEAD to that branch. git switch -c <name> does both at once - create and switch - which is what you'll use most often when starting new work.
feature/add-search, fix/login-redirect, chore/update-deps. Git doesn't enforce this, but it makes a branch list readable at a glance.Merging: combining branches back together
git merge <branch>, run while on the branch you want to merge into, brings another branch's commits into your current one. What actually happens depends on whether the two branches have diverged:
| Situation | What Git does |
|---|---|
| Target branch hasn't moved since the branches split | Fast-forward merge - Git just moves the pointer forward, no new commit created |
| Both branches have new commits since they split | Three-way merge - Git creates a new merge commit with two parents, combining both histories |
A feature branch forks off, gains its own commits, and a merge commit ties both histories back together with two parent pointers.
Deleting a branch after merging
Once a branch's work has been merged, the branch itself is just a pointer you no longer need - git branch -d <name> deletes it (Git refuses if the branch has unmerged commits, as a safety check; -D forces it). Deleting a branch doesn't delete its commits if they're still reachable through another branch, like main after a merge.