A Git branch is a named pointer to a commit that moves forward as you add new commits. Creating one gives you a separate line of development, so you can work on a feature or fix without touching the main branch.
Why it matters
Branches let several people work in parallel and keep unfinished work out of production. The usual flow is to branch from main, commit changes, open a pull request and merge the branch back once it is reviewed and tests pass. Git branches are cheap, since they are just a small file holding a commit ID.
Example
$ git switch -c add-search
$ git branch
* add-search
main
The asterisk marks your current branch. Commits made now belong to add-search only; main stays unchanged until you merge.
Common mistakes
- Letting a long-lived branch drift far from
main, which leads to painful merge conflicts. - Committing work to
mainby accident because you forgot which branch was checked out. - Never deleting merged branches, which clutters the repository.
Related
Get notified when this term updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.