Home Explore Blog CI



git

1st chunk of `Documentation/git-branch.adoc`
af7ba9a8c32b3c210d8322698bbeb828d64077a673ecba3b0000000100000fa0
git-branch(1)
=============

NAME
----
git-branch - List, create, or delete branches

SYNOPSIS
--------
[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] <branch-name> [<start-point>]
git branch (--set-upstream-to=<upstream>|-u <upstream>) [<branch-name>]
git branch --unset-upstream [<branch-name>]
git branch (-m|-M) [<old-branch>] <new-branch>
git branch (-c|-C) [<old-branch>] <new-branch>
git branch (-d|-D) [-r] <branch-name>...
git branch --edit-description [<branch-name>]

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 _<branch-name>_
which points to the current `HEAD`, or _<start-point>_ if given. As a
special case, for _<start-point>_, you may use `<rev-A>...<rev-B>` as a
shortcut for the merge base of _<rev-A>_ and _<rev-B>_ if there is exactly
one merge base. You can leave out at most one of _<rev-A>_ and _<rev-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 <new-branch>` 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, _<old-branch>_ will be renamed to _<new-branch>_.
If _<old-branch>_ had a corresponding reflog, it is renamed to match
_<new-branch>_, and a reflog entry is created to remember the branch
renaming. If _<new-branch>_ 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, _<branch-name>_ 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

Title: Git Branch Command
Summary
The git-branch command is used to list, create, or delete branches in a Git repository, with various options for filtering, renaming, and copying branches, as well as setting up tracking and merge configurations.