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 # renameOptions
| Flag | What it does |
|---|---|
| -d / --delete | Delete a merged branch |
| -D | Force-delete an unmerged branch |
| -m / --move | Rename a branch |
| -a / --all | List 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
git switch: Usage, Options & Common CI Errorsgit switch changes branches with a focused, modern interface. Reference for -c, --detach, --track, and the er…
git checkout: Usage, Options & Common CI Errorsgit checkout switches branches and restores files. Reference for -b, --detach, and pathspecs, plus the detach…
git tag: Usage, Options & Common CI Errorsgit tag creates and lists tags for releases. Reference for -a, -m, -d, pushing tags, and the "tag already exi…
git remote: Usage, Options & Common CI Errorsgit remote manages the named connections to remote repositories. Reference for add, set-url, -v, remove, and…