1 <?xml version="1.0" encoding="UTF-8"?>
\r
2 <!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd">
\r
4 <article lang="en" id="git-branch(1)">
\r
6 <title>git-branch(1)</title>
\r
8 <primary>git-branch(1)</primary>
\r
11 <simplesect id="_name">
\r
13 <simpara>git-branch - List, create, or delete branches</simpara>
\r
15 <simplesect id="_synopsis">
\r
16 <title>SYNOPSIS</title>
\r
18 <literallayout><emphasis>git branch</emphasis> [--color[=<when>] | --no-color] [-r | -a]
\r
19 [--list] [-v [--abbrev=<length> | --no-abbrev]]
\r
20 [(--merged | --no-merged | --contains) [<commit>]] [<pattern>…]
\r
21 <emphasis>git branch</emphasis> [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>]
\r
22 <emphasis>git branch</emphasis> (-m | -M) [<oldbranch>] <newbranch>
\r
23 <emphasis>git branch</emphasis> (-d | -D) [-r] <branchname>…
\r
24 <emphasis>git branch</emphasis> --edit-description [<branchname>]</literallayout>
\r
27 <simplesect id="_description">
\r
28 <title>DESCRIPTION</title>
\r
29 <simpara>With no arguments, existing branches are listed and the current branch will
\r
30 be highlighted with an asterisk. Option <emphasis>-r</emphasis> causes the remote-tracking
\r
31 branches to be listed, and option <emphasis>-a</emphasis> shows both. This list mode is also
\r
32 activated by the <emphasis>--list</emphasis> option (see below).
\r
33 <pattern> restricts the output to matching branches, the pattern is a shell
\r
34 wildcard (i.e., matched using fnmatch(3)).
\r
35 Multiple patterns may be given; if any of them matches, the branch is shown.</simpara>
\r
36 <simpara>With <emphasis>--contains</emphasis>, shows only the branches that contain the named commit
\r
37 (in other words, the branches whose tip commits are descendants of the
\r
38 named commit). With <emphasis>--merged</emphasis>, only branches merged into the named
\r
39 commit (i.e. the branches whose tip commits are reachable from the named
\r
40 commit) will be listed. With <emphasis>--no-merged</emphasis> only branches not merged into
\r
41 the named commit will be listed. If the <commit> argument is missing it
\r
42 defaults to <emphasis>HEAD</emphasis> (i.e. the tip of the current branch).</simpara>
\r
43 <simpara>The command's second form creates a new branch head named <branchname>
\r
44 which points to the current <emphasis>HEAD</emphasis>, or <start-point> if given.</simpara>
\r
45 <simpara>Note that this will create the new branch, but it will not switch the
\r
46 working tree to it; use "git checkout <newbranch>" to switch to the
\r
47 new branch.</simpara>
\r
48 <simpara>When a local branch is started off a remote-tracking branch, git sets up the
\r
49 branch so that <emphasis>git pull</emphasis> will appropriately merge from
\r
50 the remote-tracking branch. This behavior may be changed via the global
\r
51 <emphasis>branch.autosetupmerge</emphasis> configuration flag. That setting can be
\r
52 overridden by using the <emphasis>--track</emphasis> and <emphasis>--no-track</emphasis> options, and
\r
53 changed later using <emphasis>git branch --set-upstream</emphasis>.</simpara>
\r
54 <simpara>With a <emphasis>-m</emphasis> or <emphasis>-M</emphasis> option, <oldbranch> will be renamed to <newbranch>.
\r
55 If <oldbranch> had a corresponding reflog, it is renamed to match
\r
56 <newbranch>, and a reflog entry is created to remember the branch
\r
57 renaming. If <newbranch> exists, -M must be used to force the rename
\r
58 to happen.</simpara>
\r
59 <simpara>With a <emphasis>-d</emphasis> or <emphasis>-D</emphasis> option, <emphasis><branchname></emphasis> will be deleted. You may
\r
60 specify more than one branch for deletion. If the branch currently
\r
61 has a reflog then the reflog will also be deleted.</simpara>
\r
62 <simpara>Use <emphasis>-r</emphasis> together with <emphasis>-d</emphasis> to delete remote-tracking branches. Note, that it
\r
63 only makes sense to delete remote-tracking branches if they no longer exist
\r
64 in the remote repository or if <emphasis>git fetch</emphasis> was configured not to fetch
\r
65 them again. See also the <emphasis>prune</emphasis> subcommand of <xref linkend="git-remote(1)" /> for a
\r
66 way to clean up all obsolete remote-tracking branches.</simpara>
\r
68 <simplesect id="_options">
\r
69 <title>OPTIONS</title>
\r
80 Delete a branch. The branch must be fully merged in its
\r
81 upstream branch, or in <emphasis>HEAD</emphasis> if no upstream was set with
\r
82 <emphasis>--track</emphasis> or <emphasis>--set-upstream</emphasis>.
\r
92 Delete a branch irrespective of its merged status.
\r
105 Create the branch's reflog. This activates recording of
\r
106 all changes made to the branch ref, enabling use of date
\r
107 based sha1 expressions such as "<branchname>@{yesterday}".
\r
108 Note that in non-bare repositories, reflogs are usually
\r
109 enabled by default by the <emphasis>core.logallrefupdates</emphasis> config option.
\r
122 Reset <branchname> to <startpoint> if <branchname> exists
\r
123 already. Without <emphasis>-f</emphasis> <emphasis>git branch</emphasis> refuses to change an existing branch.
\r
136 Move/rename a branch and the corresponding reflog.
\r
146 Move/rename a branch even if the new branch name already exists.
\r
152 --color[=<when>]
\r
156 Color branches to highlight current, local, and
\r
157 remote-tracking branches.
\r
158 The value must be always (the default), never, or auto.
\r
168 Turn off branch colors, even when the configuration file gives the
\r
169 default to color output.
\r
170 Same as <emphasis>--color=never</emphasis>.
\r
183 List or delete (if used with -d) the remote-tracking branches.
\r
196 List both remote-tracking branches and local branches.
\r
206 Activate the list mode. <emphasis>git branch <pattern></emphasis> would try to create a branch,
\r
207 use <emphasis>git branch --list <pattern></emphasis> to list matching branches.
\r
221 show sha1 and commit subject line for each head, along with
\r
222 relationship to upstream branch (if any). If given twice, print
\r
223 the name of the upstream branch, as well.
\r
229 --abbrev=<length>
\r
233 Alter the sha1's minimum display length in the output listing.
\r
234 The default value is 7 and can be overridden by the <emphasis>core.abbrev</emphasis>
\r
245 Display the full sha1s in the output listing rather than abbreviating them.
\r
258 When creating a new branch, set up configuration to mark the
\r
259 start-point branch as "upstream" from the new branch. This
\r
260 configuration will tell git to show the relationship between the
\r
261 two branches in <emphasis>git status</emphasis> and <emphasis>git branch -v</emphasis>. Furthermore,
\r
262 it directs <emphasis>git pull</emphasis> without arguments to pull from the
\r
263 upstream when the new branch is checked out.
\r
265 <simpara>This behavior is the default when the start point is a remote-tracking branch.
\r
266 Set the branch.autosetupmerge configuration variable to <emphasis>false</emphasis> if you
\r
267 want <emphasis>git checkout</emphasis> and <emphasis>git branch</emphasis> to always behave as if <emphasis>--no-track</emphasis>
\r
268 were given. Set it to <emphasis>always</emphasis> if you want this behavior when the
\r
269 start-point is either a local or remote-tracking branch.</simpara>
\r
278 Do not set up "upstream" configuration, even if the
\r
279 branch.autosetupmerge configuration variable is true.
\r
289 If specified branch does not exist yet or if <emphasis>--force</emphasis> has been
\r
290 given, acts exactly like <emphasis>--track</emphasis>. Otherwise sets up configuration
\r
291 like <emphasis>--track</emphasis> would when creating the branch, except that where
\r
292 branch points to is not changed.
\r
302 Open an editor and edit the text to explain what the branch is
\r
303 for, to be used by various other commands (e.g. <emphasis>request-pull</emphasis>).
\r
309 --contains [<commit>]
\r
313 Only list branches which contain the specified commit (HEAD
\r
320 --merged [<commit>]
\r
324 Only list branches whose tips are reachable from the
\r
325 specified commit (HEAD if not specified).
\r
331 --no-merged [<commit>]
\r
335 Only list branches whose tips are not reachable from the
\r
336 specified commit (HEAD if not specified).
\r
346 The name of the branch to create or delete.
\r
347 The new branch name must pass all checks defined by
\r
348 <xref linkend="git-check-ref-format(1)" />. Some of these checks
\r
349 may restrict the characters allowed in a branch name.
\r
355 <start-point>
\r
359 The new branch head will point to this commit. It may be
\r
360 given as a branch name, a commit-id, or a tag. If this
\r
361 option is omitted, the current HEAD will be used instead.
\r
371 The name of an existing branch to rename.
\r
381 The new name for an existing branch. The same restrictions as for
\r
382 <branchname> apply.
\r
388 <simplesect id="_examples">
\r
389 <title>Examples</title>
\r
393 Start development from a known tag
\r
396 <screen>$ git clone git://git.kernel.org/pub/scm/.../linux-2.6 my2.6
\r
398 $ git branch my2.6.14 v2.6.14 <co id="CO1-1"/>
\r
399 $ git checkout my2.6.14</screen>
\r
401 <callout arearefs="CO1-1">
\r
403 This step and the next one could be combined into a single step with
\r
404 "checkout -b my2.6.14 v2.6.14".
\r
412 Delete an unneeded branch
\r
415 <screen>$ git clone git://git.kernel.org/.../git.git my.git
\r
417 $ git branch -d -r origin/todo origin/html origin/man <co id="CO2-1"/>
\r
418 $ git branch -D test <co id="CO2-2"/></screen>
\r
420 <callout arearefs="CO2-1">
\r
422 Delete the remote-tracking branches "todo", "html" and "man". The next
\r
423 <emphasis>fetch</emphasis> or <emphasis>pull</emphasis> will create them again unless you configure them not to.
\r
424 See <xref linkend="git-fetch(1)" />.
\r
427 <callout arearefs="CO2-2">
\r
429 Delete the "test" branch even if the "master" branch (or whichever branch
\r
430 is currently checked out) does not have all commits from the test branch.
\r
438 <simplesect id="_notes">
\r
439 <title>Notes</title>
\r
440 <simpara>If you are creating a branch that you want to checkout immediately, it is
\r
441 easier to use the git checkout command with its <emphasis>-b</emphasis> option to create
\r
442 a branch and check it out with a single command.</simpara>
\r
443 <simpara>The options <emphasis>--contains</emphasis>, <emphasis>--merged</emphasis> and <emphasis>--no-merged</emphasis> serve three related
\r
444 but different purposes:</simpara>
\r
448 <emphasis>--contains <commit></emphasis> is used to find all branches which will need
\r
449 special attention if <commit> were to be rebased or amended, since those
\r
450 branches contain the specified <commit>.
\r
455 <emphasis>--merged</emphasis> is used to find all branches which can be safely deleted,
\r
456 since those branches are fully contained by HEAD.
\r
461 <emphasis>--no-merged</emphasis> is used to find branches which are candidates for merging
\r
462 into HEAD, since those branches are not fully contained by HEAD.
\r
467 <simplesect id="_see_also">
\r
468 <title>SEE ALSO</title>
\r
469 <simpara><xref linkend="git-check-ref-format(1)" />,
\r
470 <xref linkend="git-fetch(1)" />,
\r
471 <xref linkend="git-remote(1)" />,
\r
472 <link linkend="what-is-a-branch">Understanding history: What is
\r
473 a branch?</link> in the Git User's Manual.</simpara>
\r
475 <simplesect id="_git">
\r
477 <simpara>Part of the <xref linkend="git(1)" /> suite</simpara>
\r