- Developers who already know basic commit and branch actions
- Readers who want to understand command boundaries and risk
Command Reference
git branch Tutorial
Covers how git branch lists, creates, renames, and deletes branches, and how it relates to remote-tracking branches.
- A basic mental model of worktree, index, and commits
- Comfort reading `git status` and a small commit graph
- Using local cleanup commands on already shared history
- Continuing to rewrite before confirming a recovery path
The short version
git branch manages branch refs, which are names that point at commits.
Listing branches
git branch
git branch -r
git branch -a
git branch -vv
-vv is especially useful because it shows upstream tracking information and the latest commit summary.
Creating a branch
git branch feature/login
This creates the branch but does not switch to it. For that, pair it with git switch -c or use the older checkout form.
Renaming and deleting
git branch -m old-name new-name
git branch -d feature/login
Use -D only when you deliberately want a force delete.
Local vs remote-tracking refs
People often confuse main with origin/main. The first is your local branch. The second is a remote-tracking ref updated by fetch. Understanding that distinction helps explain many sync workflows.
What problem this command solves in a workflow
git branch operates at the reference layer, responsible for creating, renaming, listing, and deleting branches. It does not touch working tree content or the staging area — its core duty is managing "names that point at commits," letting you organize work across different development lines.
Typical use cases
- Use
git branchto list all local branches and quickly understand what development lines exist. - Use
git branch -vvto see each branch's upstream tracking relationship and latest commit — a frequent pattern for diagnosing sync status. - Use
git branch -dto safely delete already-merged branches and keep the branch list tidy; confirm you want a force delete with-D.
Diagram view
Special cases and boundaries
git branchcreates branch refs only; it does not switch to them — usegit switchfor that.- Deleting a branch does not delete commits: as long as other refs or the reflog still point at them, the commit objects remain.
git branch -drefuses to delete unmerged branches as a safety measure; use-Dto force when you are sure.- Remote-tracking refs (e.g.,
origin/main) and local branches (e.g.,main) are independent: fetch updates the former, and you need merge or rebase to integrate into the latter.