git branch
List, create, rename, or delete branches
Practical Example
git branch feature-login # create branch at current commit git branch -d feature-login # delete after merging git branch -a # list all local and remote branches
Command Overview & How It Works
A branch is a lightweight, movable pointer to a specific commit. Use git branch without arguments to list all local branches — the current branch is highlighted with an asterisk. Create a new branch with git branch <name>, which creates a pointer at the current commit without switching to it. Use git branch -d <name> to delete a merged branch safely, or git branch -D to force-delete an unmerged branch. Rename a branch with git branch -m <old> <new>. List remote branches with git branch -r, and all branches (local + remote) with git branch -a. The git branch -vv command shows which remote branch each local branch is tracking. Branch names should be descriptive and use hyphens as separators — like feature-login or hotfix-security-patch.
Practical Tips
- •Name branches descriptively with hyphens, such as feature/login or hotfix/payment-timeout.
- •Use git branch -vv to see which remote branch each local branch tracks.
- •Delete merged branches with git branch -d (safe); reserve -D for work you are certain you can lose.