A Git branch is a separate, movable line of work inside one project. It lets you build a feature or test an idea without changing the main version until you decide it is ready. Technically a branch is just a lightweight pointer to a commit; as you make new commits, the pointer moves forward, so the branch always points at the latest work on that line. Because it is only a pointer, creating a branch is nearly instant, which is why developers make them freely.
What a branch actually is
Most people picture a branch as a copy of all their files. It is not. Git stores your history as a chain of commits, and a branch is simply a named pointer to one of those commits. The default branch is usually called main. When you create a new branch, Git adds a second pointer at the same commit, then moves that pointer along as you commit on the new branch. Nothing is duplicated, which is why branching is cheap and fast even on a large project.
There is also a special pointer called HEAD that tracks which branch you are currently on. Switching branches just moves HEAD and updates your files to match that line of work. If you are brand new to all this, it helps to first see how to use Git and GitHub together.
How branches work in practice
The everyday flow is short. You create a branch off main, make commits on it, then merge it back when the work is solid.
git switch -c add-search // create a branch and move onto it
git add .
git commit -m "add search box" // this commit lands only on add-search
git switch main // back to the main line, untouched
git merge add-search // bring the finished work into main
While you are on add-search, main does not change at all. Your experiment is fully isolated. If the idea fails, you switch back to main and delete the branch, and your main history is exactly as it was.
Branch versus commit: the difference
| Concept |
What it is |
Moves? |
| Commit |
A fixed snapshot of your project at one moment |
No, it is permanent |
| Branch |
A named pointer to a commit |
Yes, advances with each new commit |
| HEAD |
A pointer to the branch you are currently on |
Yes, when you switch branches |
| Tag |
A fixed label on one commit, often a release |
No, stays put |
The short version: a commit is the thing that is saved; a branch is a label that walks forward along the commits. Confusing the two is the most common beginner stumble.
How to use branches well
- Branch for every distinct piece of work, even small ones, so main always stays releasable.
- Give branches clear names like
fix-login-bug rather than test or your initials.
- Keep branches short-lived. Merge within days, not weeks, so they do not drift far from main.
- Pull the latest main into your branch regularly to surface conflicts early instead of all at once.
- Delete a branch after it merges. Stale branches pile up and confuse everyone.
What to skip
- Skip long-lived branches. A branch alive for a month will be painful to merge. Smaller, frequent merges hurt less.
- Skip committing straight to main on a team. Use a branch and a review so main stays trustworthy.
- Skip cryptic branch names. Future you will not remember what
temp2 was for.
- Skip fear of deleting branches. The commits live on after a merge; deleting the pointer loses nothing.
FAQ
Is a branch a copy of my files?
No. A branch is just a pointer to a commit. Git updates your working files when you switch branches, but it does not store a separate copy of the whole project for each branch.
What is the main branch?
The default line of work, usually named main. It is meant to hold the stable, releasable version of your project. Other branches are merged into it once their work is ready.
What happens to a branch after I merge it?
The commits become part of the branch you merged into, so the work is preserved. The branch pointer itself is no longer needed, and most teams delete it to keep things tidy.
Can two people work on different branches at once?
Yes, that is a core reason branches exist. Each person works in isolation on their own branch and merges back into main when ready, avoiding constant collisions.
Where to go next
See how a commit saves a snapshot, understand what a Git repository holds, and learn the difference between Git and GitHub.