Skip to content

Commit 382a491

Browse files
committed
doc: git-checkout: clarify -b
- Remove some unnecessary detail about `--track` (users can refer to the OPTIONS section instead) - Explain what the start point defaults to - Describe `-B` much more tersely as "the same as `-b`, except ..", since potential users of `-B` are almost certainly already very familiar with `-b`. Move all of the other contents of `-B` to `-b`, updating the example so that it's appropriate for `-b` Signed-off-by: Julia Evans <[email protected]>
1 parent a4c0f96 commit 382a491

File tree

1 file changed

+18
-26
lines changed

1 file changed

+18
-26
lines changed

Documentation/git-checkout.adoc

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,21 @@ $ git checkout -b <branch> --track <remote>/<branch>
4646
Running `git checkout` without specifying a branch has no effect except
4747
to print out the tracking information for the current branch.
4848
49-
`git checkout (-b|-B) <new-branch> [<start-point>]`::
50-
51-
Specifying `-b` causes a new branch to be created as if
52-
linkgit:git-branch[1] were called and then checked out. In
53-
this case you can use the `--track` or `--no-track` options,
54-
which will be passed to `git branch`. As a convenience,
55-
`--track` without `-b` implies branch creation; see the
56-
description of `--track` below.
57-
+
58-
If `-B` is given, _<new-branch>_ is created if it doesn't exist; otherwise, it
59-
is reset. This is the transactional equivalent of
60-
+
61-
------------
62-
$ git branch -f <branch> [<start-point>]
63-
$ git checkout <branch>
64-
------------
49+
`git checkout -b <new-branch> [<start-point>]`::
50+
51+
Create a new branch named _<new-branch>_, start it at _<start-point>_
52+
(defaults to the current commit), and check out the new branch.
53+
You can use the `--track` or `--no-track` options to set the branch's
54+
upstream tracking information.
6555
+
66-
that is to say, the branch is not reset/created unless "git checkout" is
67-
successful (e.g., when the branch is in use in another worktree, not
68-
just the current branch stays the same, but the branch is not reset to
69-
the start-point, either).
56+
This fails without making any changes if there's an error checking out
57+
_<new-branch>_, for example if checking out the `<start-point>`
58+
commit would overwrite your uncommitted changes.
59+
60+
`git checkout -B <branch> [<start-point>]`::
61+
62+
The same as `-b`, except that if the branch already exists it
63+
resets `_<branch>_` to the start point instead of creating it.
7064
7165
`git checkout --detach [<branch>]`::
7266
`git checkout [--detach] <commit>`::
@@ -156,16 +150,14 @@ of it").
156150
see linkgit:git-branch[1] for details.
157151
158152
`-B <new-branch>`::
159-
Creates the branch _<new-branch>_, start it at _<start-point>_;
160-
if it already exists, then reset it to _<start-point>_. And then
161-
check the resulting branch out. This is equivalent to running
162-
`git branch` with `-f` followed by `git checkout` of that branch;
163-
see linkgit:git-branch[1] for details.
153+
The same as `-b`, except that if the branch already exists it
154+
resets `_<branch>_` to the start point instead of creating it.
164155
165156
`-t`::
166157
`--track[=(direct|inherit)]`::
167158
When creating a new branch, set up "upstream" configuration. See
168-
`--track` in linkgit:git-branch[1] for details.
159+
`--track` in linkgit:git-branch[1] for details. As a convenience,
160+
--track without -b implies branch creation.
169161
+
170162
If no `-b` option is given, the name of the new branch will be
171163
derived from the remote-tracking branch, by looking at the local part of

0 commit comments

Comments
 (0)