Git 2 reference · Branching and Merging
git branch Command (Git)
List, create, rename and delete branches, and see which branches are merged.
Git 2
Syntax
git branch [NAME] [-d|-D NAME] [-m OLD NEW] [-v] [--merged]
Parameters
| Parameter | Description |
|---|---|
NAME |
Create a branch at the current commit. |
-d / -D |
Delete (only if merged) / force delete. |
-m |
Rename. |
-v / -vv |
Show the last commit / upstream tracking. |
--merged |
Branches already merged into the current one. |
Examples
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git branch feature/login
git branch hotfix
git branch
Output
feature/login hotfix * main
Run this on your computer — see “Get Started” for setup.
git init -q -b main app && cd app
echo '# Shop' > README.md
git add README.md && git commit -q -m 'Initial commit'
git branch old-idea
git branch -m old-idea archived-idea
git branch --merged
git branch -d archived-idea
Output
archived-idea * main Deleted branch archived-idea (was 7f7f133).
Run this on your computer — see “Get Started” for setup.
Related
git switch· Switch to another branch, or create one and switch to it with -c; the modern replacement for git checkout branches.git merge· Combine another branch into the current one, fast-forwarding when possible or creating a merge commit.- Branches · tutorial