How to List, Create, and Delete Branches in Git (git branch)
git branch manages branches — separate, independent lines of development within the same repository.
Published September 27, 2026
git branch lists, creates and deletes branches. A branch is just a movable pointer to a commit, so creating one is instant and cheap.
How it works
Branches let you work on features in isolation. git branch alone lists local branches; -a includes remote ones.
Delete merged branches with -d and force-delete unmerged ones with -D.
Try it
git branch feature-search
git branch
* main feature-search
git branch -d feature-search
Deleted branch feature-search
Practical examples
Create and switch
git switch -c feature-searchList all branches
git branch -aDelete a merged branch
git branch -d feature-searchRename
git branch -m old-name new-nameCommon mistakes
- Using -D and losing unmerged work.
- Forgetting to delete remote branches too.
- Creating a branch but staying on the old one.
Key takeaways
- Branches are cheap pointers.
- -d safe delete, -D force.
- git switch -c creates and switches.
FAQ
How do I see merged branches?
git branch --merged.
Branch vs tag?
Branches move with new commits; tags stay fixed.