Man page - git-branch(1)
Packages contas this manual
- git-fsmonitor--daemon(1)
- git(1)
- gitprotocol-v2(5)
- gitweb(1)
- git-repack(1)
- git-reset(1)
- git-fetch-pack(1)
- git-daemon(1)
- git-subtree(1)
- git-fmt-merge-msg(1)
- git-diff-index(1)
- git-pack-redundant(1)
- git-ls-remote(1)
- git-mktree(1)
- git-count-objects(1)
- gitformat-commit-graph(5)
- git-worktree(1)
- git-verify-commit(1)
- gitmailmap(5)
- gitformat-bundle(5)
- gitcli(7)
- git-mailinfo(1)
- git-tag(1)
- git-remote(1)
- git-symbolic-ref(1)
- scalar(1)
- git-patch-id(1)
- git-interpret-trailers(1)
- git-init-db(1)
- gitremote-helpers(7)
- git-maintenance(1)
- git-mergetool(1)
- git-stage(1)
- git-diff-files(1)
- git-shortlog(1)
- git-submodule(1)
- git-cat-file(1)
- git-am(1)
- git-check-mailmap(1)
- git-add(1)
- git-write-tree(1)
- git-pack-objects(1)
- git-version(1)
- git-receive-pack(1)
- git-verify-tag(1)
- git-reflog(1)
- gitcredentials(7)
- gitrepository-layout(5)
- git-send-pack(1)
- gitignore(5)
- git-merge-file(1)
- git-http-push(1)
- git-credential-cache--daemon(1)
- git-merge-index(1)
- git-get-tar-commit-id(1)
- git-merge-one-file(1)
- git-remote-ext(1)
- git-blame(1)
- git-fetch(1)
- git-prune(1)
- git-bisect(1)
- git-replace(1)
- gitformat-chunk(5)
- gitglossary(7)
- git-show(1)
- git-rm(1)
- git-commit(1)
- gitcore-tutorial(7)
- git-merge(1)
- gitformat-pack(5)
- git-fsck(1)
- gitworkflows(7)
- git-name-rev(1)
- git-diagnose(1)
- git-log(1)
- git-whatchanged(1)
- git-check-attr(1)
- git-refs(1)
- git-gc(1)
- git-unpack-file(1)
- git-mailsplit(1)
- git-switch(1)
- git-sparse-checkout(1)
- git-multi-pack-index(1)
- gitprotocol-pack(5)
- git-init(1)
- git-rev-parse(1)
- git-merge-tree(1)
- gittutorial(7)
- git-request-pull(1)
- git-check-ref-format(1)
- git-mv(1)
- git-rev-list(1)
- git-bugreport(1)
- git-mktag(1)
- git-sh-i18n--envsubst(1)
- git-range-diff(1)
- git-notes(1)
- git-checkout-index(1)
- git-show-branch(1)
- gitprotocol-http(5)
- git-sh-setup(1)
- gitweb.conf(5)
- gitnamespaces(7)
- git-grep(1)
- gittutorial-2(7)
- git-fsck-objects(1)
- giteveryday(7)
- git-config(1)
- git-prune-packed(1)
- git-help(1)
- git-apply(1)
- git-fast-import(1)
- gitprotocol-capabilities(5)
- git-mergetool--lib(1)
- git-diff-tree(1)
- git-instaweb(1)
- git-difftool(1)
- git-pack-refs(1)
- git-restore(1)
- gitsubmodules(7)
- git-annotate(1)
- gitattributes(5)
- git-credential-store(1)
- git-ls-files(1)
- git-var(1)
- git-remote-fd(1)
- gitformat-index(5)
- gitrevisions(7)
- git-unpack-objects(1)
- git-diff(1)
- git-commit-tree(1)
- git-for-each-repo(1)
- git-web--browse(1)
- git-update-index(1)
- gitpacking(7)
- git-imap-send(1)
- git-show-ref(1)
- git-replay(1)
- git-for-each-ref(1)
- git-http-fetch(1)
- gitprotocol-common(5)
- git-cherry(1)
- git-merge-base(1)
- git-fast-export(1)
- git-column(1)
- git-upload-pack(1)
- gitfaq(7)
- git-stash(1)
- gitmodules(5)
- git-push(1)
- git-cherry-pick(1)
- gitformat-signature(5)
- git-verify-pack(1)
- githooks(5)
- git-hook(1)
- git-pull(1)
- git-http-backend(1)
- git-filter-branch(1)
- git-stripspace(1)
- git-rebase(1)
- git-revert(1)
- git-show-index(1)
- git-branch(1)
- git-quiltimport(1)
- gitdiffcore(7)
- gitcvs-migration(7)
- git-checkout(1)
- git-upload-archive(1)
- git-check-ignore(1)
- git-shell(1)
- git-update-server-info(1)
- git-bundle(1)
- git-hash-object(1)
- git-clone(1)
- git-commit-graph(1)
- git-update-ref(1)
- git-status(1)
- git-describe(1)
- git-sh-i18n(1)
- git-archive(1)
- git-clean(1)
- git-read-tree(1)
- git-rerere(1)
- git-index-pack(1)
- git-credential-cache(1)
- git-credential(1)
- git-format-patch(1)
- git-ls-tree(1)
apt-get install git-man
Manual
| GIT-BRANCH(1) | Git Manual | GIT-BRANCH(1) |
NAME
git-branch - List, create, or delete branches
SYNOPSIS
git branch [--color[=<when>] | --no-color] [--show-current]
[-v [--abbrev=<n> | --no-abbrev]]
[--column[=<options>] | --no-column] [--sort=<key>]
[--merged [<commit>]] [--no-merged [<commit>]]
[--contains [<commit>]] [--no-contains [<commit>]]
[--points-at <object>] [--format=<format>]
[(-r | --remotes) | (-a | --all)]
[--list] [<pattern>...] git branch [--track[=(direct|inherit)] | --no-track] [-f]
[--recurse-submodules] <branchname> [<start-point>] git branch (--set-upstream-to=<upstream> | -u <upstream>) [<branchname>] git branch --unset-upstream [<branchname>] git branch (-m | -M) [<oldbranch>] <newbranch> git branch (-c | -C) [<oldbranch>] <newbranch> git branch (-d | -D) [-r] <branchname>... git branch --edit-description [<branchname>]
DESCRIPTION
If --list is given, or if there are no non-option arguments, existing branches are listed; the current branch will be highlighted in green and marked with an asterisk. Any branches checked out in linked worktrees will be highlighted in cyan and marked with a plus sign. Option -r causes the remote-tracking branches to be listed, and option -a shows both local and remote branches.
If a <pattern> is given, it is used as a shell wildcard to restrict the output to matching branches. If multiple patterns are given, a branch is shown if it matches any of the patterns.
Note that when providing a <pattern>, you must use --list; otherwise the command may be interpreted as branch creation.
With --contains, shows only the branches that contain the named commit (in other words, the branches whose tip commits are descendants of the named commit), --no-contains inverts it. With --merged, only branches merged into the named commit (i.e. the branches whose tip commits are reachable from the named commit) will be listed. With --no-merged only branches not merged into the named commit will be listed. If the <commit> argument is missing it defaults to HEAD (i.e. the tip of the current branch).
The command’s second form creates a new branch head named <branchname> which points to the current HEAD, or <start-point> if given. As a special case, for <start-point>, you may use "A...B" as a shortcut for the merge base of A and B if there is exactly one merge base. You can leave out at most one of A and B, in which case it defaults to HEAD.
Note that this will create the new branch, but it will not switch the working tree to it; use "git switch <newbranch>" to switch to the new branch.
When a local branch is started off a remote-tracking branch, Git sets up the branch (specifically the branch.<name>.remote and branch.<name>.merge configuration entries) so that git pull will appropriately merge from the remote-tracking branch. This behavior may be changed via the global branch.autoSetupMerge configuration flag. That setting can be overridden by using the --track and --no-track options, and changed later using git branch --set-upstream-to.
With a -m or -M option, <oldbranch> will be renamed to <newbranch>. If <oldbranch> had a corresponding reflog, it is renamed to match <newbranch>, and a reflog entry is created to remember the branch renaming. If <newbranch> exists, -M must be used to force the rename to happen.
The -c and -C options have the exact same semantics as -m and -M, except instead of the branch being renamed, it will be copied to a new name, along with its config and reflog.
With a -d or -D option, <branchname> will be deleted. You may specify more than one branch for deletion. If the branch currently has a reflog then the reflog will also be deleted.
Use -r together with -d to delete remote-tracking branches. Note, that it only makes sense to delete remote-tracking branches if they no longer exist in the remote repository or if git fetch was configured not to fetch them again. See also the prune subcommand of git-remote(1) for a way to clean up all obsolete remote-tracking branches.
OPTIONS
-d, --delete
-D
--create-reflog
-f, --force
Note that git branch -f <branchname> [<start-point>], even with -f, refuses to change an existing branch <branchname> that is checked out in another worktree linked to the same repository.
-m, --move
-M
-c, --copy
-C
--color[=<when>]
--no-color
-i, --ignore-case
--omit-empty
--column[=<options>], --no-column
This option is only applicable in non-verbose mode.
-r, --remotes
-a, --all
-l, --list
--show-current
-v, -vv, --verbose
-q, --quiet
--abbrev=<n>
--no-abbrev
-t, --track[=(direct|inherit)]
The exact upstream branch is chosen depending on the optional argument: -t, --track, or --track=direct means to use the start-point branch itself as the upstream; --track=inherit means to copy the upstream configuration of the start-point branch.
The branch.autoSetupMerge configuration variable specifies how git switch, git checkout and git branch should behave when neither --track nor --no-track are specified:
The default option, true, behaves as though --track=direct were given whenever the start-point is a remote-tracking branch. false behaves as if --no-track were given. always behaves as though --track=direct were given. inherit behaves as though --track=inherit were given. simple behaves as though --track=direct were given only when the start-point is a remote-tracking branch and the new branch has the same name as the remote branch.
See git-pull(1) and git-config(1) for additional discussion on how the branch.<name>.remote and branch.<name>.merge options are used.
--no-track
--recurse-submodules
When used in branch creation, a new branch <branchname> will be created in the superproject and all of the submodules in the superproject’s <start-point>. In submodules, the branch will point to the submodule commit in the superproject’s <start-point> but the branch’s tracking information will be set up based on the submodule’s branches and remotes e.g. git branch --recurse-submodules topic origin/main will create the submodule branch "topic" that points to the submodule commit in the superproject’s "origin/main", but tracks the submodule’s "origin/main".
--set-upstream
-u <upstream>, --set-upstream-to=<upstream>
--unset-upstream
--edit-description
--contains [<commit>]
--no-contains [<commit>]
--merged [<commit>]
--no-merged [<commit>]
<branchname>
<start-point>
<oldbranch>
<newbranch>
--sort=<key>
--points-at <object>
--format <format>
CONFIGURATION
pager.branch is only respected when listing branches, i.e., when --list is used or implied. The default is to use a pager. See git-config(1).
Everything above this line in this section isn’t included from the git-config(1) documentation. The content that follows is the same as what’s found there:
branch.autoSetupMerge
branch.autoSetupRebase
branch.sort
branch.<name>.remote
branch.<name>.pushRemote
branch.<name>.merge
branch.<name>.mergeOptions
branch.<name>.rebase
When merges (or just m), pass the --rebase-merges option to git rebase so that the local merge commits are included in the rebase (see git-rebase(1) for details).
When the value is interactive (or just i), the rebase is run in interactive mode.
NOTE: this is a possibly dangerous operation; do not use it unless you understand the implications (see git-rebase(1) for details).
branch.<name>.description
EXAMPLES
Start development from a known tag
$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6 $ cd my2.6 $ git branch my2.6.14 v2.6.14 (1) $ git switch my2.6.14
| 1. | This step and the next one could be combined into a single step with "checkout -b my2.6.14 v2.6.14". |
Delete an unneeded branch
$ git clone git://git.kernel.org/.../git.git my.git $ cd my.git $ git branch -d -r origin/todo origin/html origin/man (1) $ git branch -D test (2)
| 1. | Delete the remote-tracking branches "todo", "html" and "man". The next fetch or pull will create them again unless you configure them not to. See git-fetch(1). |
| 2. | Delete the "test" branch even if the "master" branch (or whichever branch is currently checked out) does not have all commits from the test branch. |
Listing branches from a specific remote
$ git branch -r -l '<remote>/<pattern>' (1) $ git for-each-ref 'refs/remotes/<remote>/<pattern>' (2)
| 1. | Using -a would conflate <remote> with any local branches you happen to have been prefixed with the same <remote> pattern. |
| 2. | for-each-ref can take a wide range of options. See git-for-each-ref(1) |
Patterns will normally need quoting.
NOTES
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.
The options --contains, --no-contains, --merged and --no-merged serve four related but different purposes:
When combining multiple --contains and --no-contains filters, only references that contain at least one of the --contains commits and contain none of the --no-contains commits are shown.
When combining multiple --merged and --no-merged filters, only references that are reachable from at least one of the --merged commits and from none of the --no-merged commits are shown.
SEE ALSO
git-check-ref-format(1), git-fetch(1), git-remote(1), “Understanding history: What is a branch?”[1] in the Git User’s Manual.
GIT
Part of the git(1) suite
NOTES
- 1.
- “Understanding history: What is a branch?”
| 07/30/2025 | Git 2.47.3 |