Skip to content

Commit a7b5e91

Browse files
committed
Merge branch 'cr/doc-checkout-branch' into maint
* cr/doc-checkout-branch: Documentation/git-checkout.txt: document 70c9ac2 behavior Documentation/git-checkout.txt: clarify usage
2 parents 2b19658 + 00bb437 commit a7b5e91

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

Documentation/git-checkout.txt

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,34 @@ or the specified tree. If no paths are given, 'git checkout' will
2121
also update `HEAD` to set the specified branch as the current
2222
branch.
2323

24-
'git checkout' [<branch>]::
24+
'git checkout' <branch>::
25+
To prepare for working on <branch>, switch to it by updating
26+
the index and the files in the working tree, and by pointing
27+
HEAD at the branch. Local modifications to the files in the
28+
working tree are kept, so that they can be committed to the
29+
<branch>.
30+
+
31+
If <branch> is not found but there does exist a tracking branch in
32+
exactly one remote (call it <remote>) with a matching name, treat as
33+
equivalent to
34+
+
35+
------------
36+
$ git checkout -b <branch> --track <remote>/<branch>
37+
------------
38+
+
39+
You could omit <branch>, in which case the command degenerates to
40+
"check out the current branch", which is a glorified no-op with a
41+
rather expensive side-effects to show only the tracking information,
42+
if exists, for the current branch.
43+
2544
'git checkout' -b|-B <new_branch> [<start point>]::
26-
'git checkout' [--detach] [<commit>]::
2745

28-
This form switches branches by updating the index, working
29-
tree, and HEAD to reflect the specified branch or commit.
30-
+
31-
If `-b` is given, a new branch is created as if linkgit:git-branch[1]
32-
were called and then checked out; in this case you can
33-
use the `--track` or `--no-track` options, which will be passed to
34-
'git branch'. As a convenience, `--track` without `-b` implies branch
35-
creation; see the description of `--track` below.
46+
Specifying `-b` causes a new branch to be created as if
47+
linkgit:git-branch[1] were called and then checked out. In
48+
this case you can use the `--track` or `--no-track` options,
49+
which will be passed to 'git branch'. As a convenience,
50+
`--track` without `-b` implies branch creation; see the
51+
description of `--track` below.
3652
+
3753
If `-B` is given, <new_branch> is created if it doesn't exist; otherwise, it
3854
is reset. This is the transactional equivalent of
@@ -45,6 +61,21 @@ $ git checkout <branch>
4561
that is to say, the branch is not reset/created unless "git checkout" is
4662
successful.
4763

64+
'git checkout' --detach [<branch>]::
65+
'git checkout' <commit>::
66+
67+
Prepare to work on top of <commit>, by detaching HEAD at it
68+
(see "DETACHED HEAD" section), and updating the index and the
69+
files in the working tree. Local modifications to the files
70+
in the working tree are kept, so that the resulting working
71+
tree will be the state recorded in the commit plus the local
72+
modifications.
73+
+
74+
Passing `--detach` forces this behavior in the case of a <branch> (without
75+
the option, giving a branch name to the command would check out the branch,
76+
instead of detaching HEAD at it), or the current commit,
77+
if no <branch> is specified.
78+
4879
'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
4980

5081
When <paths> or `--patch` are given, 'git checkout' does *not*

0 commit comments

Comments
 (0)