Home Explore Blog CI



git

6th chunk of `Documentation/git-branch.adoc`
509264c4e5bd060ce9630f50725f640882e99360479ea5340000000100000cc2
 in a branch name.

_<start-point>_::
	The new branch head will point to this commit.  It may be
	given as a branch name, a commit-id, or a tag.  If this
	option is omitted, the current `HEAD` will be used instead.

_<old-branch>_::
	The name of an existing branch.  If this option is omitted,
	the name of the current branch will be used instead.

_<new-branch>_::
	The new name for an existing branch. The same restrictions as for
	_<branch-name>_ apply.

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 linkgit:git-config[1].

include::includes/cmd-config-section-rest.adoc[]

include::config/branch.adoc[]

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
    `git fetch` or `git pull` will create them again unless you configure them not to.
    See linkgit: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 linkgit: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:

- `--contains <commit>` is used to find all branches which will need
  special attention if _<commit>_ were to be rebased or amended, since those
  branches contain the specified _<commit>_.

- `--no-contains <commit>` is the inverse of that, i.e. branches that don't
  contain the specified _<commit>_.

- `--merged` is used to find all branches which can be safely deleted,
  since those branches are fully contained by `HEAD`.

- `--no-merged` is used to find branches which are candidates for merging
  into `HEAD`, since those branches are not fully contained by `HEAD`.

include::ref-reachability-filters.adoc[]

SEE ALSO
--------
linkgit:git-check-ref-format[1],
linkgit:git-fetch[1],
linkgit:git-remote[1],
link:user-manual.html#what-is-a-branch["Understanding history: What is
a branch?"] in the Git User's Manual.

GIT
---
Part of the linkgit:git[1] suite

Title: Git Branch Command Usage and Options
Summary
The git branch command is used to create, delete, and manage branches, with various options for filtering and listing branches, such as --contains and --merged, and configuration settings like pager.branch, along with examples of common use cases and explanations of related concepts like ref reachability filters.