Synopsis
Description
List, create, or delete branches. The current branch will be highlighted and marked with an asterisk. If--list is given, or if there are no non-option arguments, existing branches are listed.
When creating a new branch, it will be created based on the current HEAD or the specified <start-point>. Note that this will create the new branch, but it will not switch the working tree to it; use git switch <new-branch> to switch to the new branch.
Common Usage
Options
-d, --delete
-d, --delete
Delete a branch. The branch must be fully merged in its upstream branch, or in
HEAD if no upstream was set.-D
-D
Shortcut for
--delete --force. Delete the branch irrespective of its merged status.-m, --move
-m, --move
Move/rename a branch, together with its config and reflog.
-M
-M
Shortcut for
--move --force. Rename even if the new branch name already exists.-c, --copy
-c, --copy
Copy a branch, together with its config and reflog.
-r, --remotes
-r, --remotes
List or delete remote-tracking branches.
-a, --all
-a, --all
List both remote-tracking branches and local branches.
-v, -vv, --verbose
-v, -vv, --verbose
Show SHA1 and commit subject line for each head. If given twice, print the path of the linked worktree and the name of the upstream branch.
--show-current
--show-current
Print the name of the current branch. In detached HEAD state, nothing is printed.
--list
--list
List branches. With optional pattern, list only the branches that match.
-u, --set-upstream-to
-u, --set-upstream-to
Set up branch’s tracking information so upstream is considered the branch’s upstream branch.
--unset-upstream
--unset-upstream
Remove the upstream information for a branch.
--contains
--contains
Only list branches which contain the specified commit.
--merged
--merged
Only list branches whose tips are reachable from the specified commit (default: HEAD).
--no-merged
--no-merged
Only list branches whose tips are not reachable from the specified commit.
Examples
Start development from a known tag
Delete branches
List branches from a specific remote
Working with tracking information
Find branches with specific commits
If you are creating a branch that you want to switch to immediately, it is easier to use the
git switch command with its -c option to do the same thing with a single command:Related Commands
- git checkout - Switch branches or restore working tree files
- git switch - Switch to a branch
- git merge - Join two or more development histories together
- git remote - Manage set of tracked repositories
