Git 2 reference · Branching and Merging

git branch Command (Git)

List, create, rename and delete branches, and see which branches are merged.

Git 2

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

git branch [NAME] [-d|-D NAME] [-m OLD NEW] [-v] [--merged]

Parameters

ParameterDescription
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

Create and list
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.

Rename, check merged, delete
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.

Was this page helpful?