git branch
Manage branches: create, list, rename, and delete branches
Syntax
git branch [<options>] [<branchname>] [<start-point>]
Parameters
| Parameters | Description | Examples | Level |
|---|---|---|---|
-a --all |
(+) | git branch -a |
Common |
-d --delete |
git branch -d feature-x |
Common | |
-D |
() | git branch -D experiment |
|
-m --move |
git branch -m old-name new-name |
Common | |
-v --verbose |
git branch -v |
Common |
Examples
New
git branch feature-login
git branch -a
git branch -d feature-done
git branch -m new-name
git branch --merged
Common Errors
error: branch 'x' not found, git branch -a
error: The branch 'x' is not fully merged, -D
Tips
- git branch --merged | grep -v main | xargs git branch -d
- git switch git checkout (Git 2.23+)