Skip to content
Latchkey

git branch: Usage, Options & Common CI Errors

git branch manages your branches: list them, make them, rename them, delete them.

Use git branch for branch bookkeeping; use switch/checkout to actually move onto a branch.

What it does

git branch with no arguments lists local branches. With a name it creates a branch; with flags it deletes, renames, or lists branches by various filters.

Common usage

Terminal
git branch                    # list local branches
git branch -a                 # include remote-tracking branches
git branch feature            # create (does not switch)
git branch -d feature         # delete if merged
git branch -m old new         # rename

Options

FlagWhat it does
-d / --deleteDelete a merged branch
-DForce-delete an unmerged branch
-m / --moveRename a branch
-a / --allList local and remote-tracking branches
--set-upstream-to=<ref>Set the tracked upstream

Common errors in CI

error: The branch 'X' is not fully merged. If you are sure you want to delete it, run 'git branch -D X' - git -d protects unmerged work. Use -D to force. Listing only shows what was cloned, so -a may miss branches if the clone was single-branch.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →