By admin , 29 April 2026

Synopsis

git branch [-a] [-r] [-v] [-d <name>] [-m <old> <new>] [<name> [<start-point>]]

Description

The git branch command manages branches. With no arguments it lists local branches and marks the current one with an asterisk. Given a name, it creates a new branch pointing at the current HEAD (or at a specified start point). It can also delete, rename, and inspect branches. A branch in Git is a lightweight, movable pointer to a commit — creating one is essentially free, which is why Git workflows encourage many short-lived branches.

Note: git branch <name> creates a branch but does not switch to it. To create and switch in one step, use git switch -c <name> or git checkout -b <name>. The --track behavior makes a new branch follow a remote branch for push/pull defaults.

In day-to-day use, git branch integrates closely with shell aliases, editor plugins, and continuous integration. Power users often add aliases that combine flags they always pass, or wrap the command in scripts that enforce team conventions. Output formatting can be customized via Git config — pretty formats, color schemes, and pager behavior are all tunable. When something goes wrong, the first diagnostic step is usually to re-run the command with GIT_TRACE=1 in the environment, which reveals the underlying plumbing calls. For unusual situations, the --help output (git branch --help) opens the full manual page with details on every option, including those rarely used in casual workflows but essential for debugging or scripting at scale.

Understanding how git branch interacts with the rest of Git's data model — the object database, the index, refs, and the working tree — pays dividends. Each command operates on some subset of these pieces, and knowing which it touches helps predict outcomes and recover from mistakes. Reading the official Git documentation alongside hands-on practice in a throwaway repository is the fastest way to internalize the nuances. Most production issues with Git stem from one of three causes: surprising default behavior, partial network operations, or rewriting history that was already shared. A working mental model of git branch's side effects helps avoid all three.

Common Options

OptionDescription
-a, --allList both local and remote-tracking branches.
-r, --remotesList only remote-tracking branches.
-v, --verboseShow the latest commit on each branch.
-d <name>Delete a fully merged branch.
-D <name>Force-delete a branch even if it isn't merged.
-m <old> <new>Rename a branch.
--merged / --no-mergedFilter branches that are (not) merged into HEAD.
--set-upstream-to=<remote>/<branch>Configure tracking for the current branch.

Examples

git branch
# List local branches

git branch feature/login
# Create a new branch from current HEAD

git branch -d old-feature
# Delete a merged branch

git branch -m main trunk
# Rename the local branch main to trunk

git branch -a -v
# List all branches (local + remote) with last commits

Common Mistakes

Using -D to force-delete a branch can lose unmerged commits forever (well, until git reflog expires). Always try -d first. Renaming the current branch with -m works without arguments — git branch -m new-name renames whatever you're on. Forgetting to set upstream tracking after creating a branch means git push may need explicit arguments the first time.

Related Commands

git switch, git checkout, git merge, git push