1
0
mirror of https://github.com/git/git.git synced 2024-10-19 14:08:16 +02:00

Merge branch 'cr/doc-checkout-branch'

Document the magic "git checkout <no-such-branch>" hack to create
local branch out of a remote tracking branch that hasn't been
documented so far.

* cr/doc-checkout-branch:
  Documentation/git-checkout.txt: document 70c9ac2 behavior
  Documentation/git-checkout.txt: clarify usage
This commit is contained in:
Junio C Hamano 2012-12-21 15:19:08 -08:00
commit 51bf6bea51

@ -21,18 +21,34 @@ or the specified tree. If no paths are given, 'git checkout' will
also update `HEAD` to set the specified branch as the current also update `HEAD` to set the specified branch as the current
branch. branch.
'git checkout' [<branch>]:: 'git checkout' <branch>::
'git checkout' -b|-B <new_branch> [<start point>]:: To prepare for working on <branch>, switch to it by updating
'git checkout' [--detach] [<commit>]:: the index and the files in the working tree, and by pointing
HEAD at the branch. Local modifications to the files in the
This form switches branches by updating the index, working working tree are kept, so that they can be committed to the
tree, and HEAD to reflect the specified branch or commit. <branch>.
+ +
If `-b` is given, a new branch is created as if linkgit:git-branch[1] If <branch> is not found but there does exist a tracking branch in
were called and then checked out; in this case you can exactly one remote (call it <remote>) with a matching name, treat as
use the `--track` or `--no-track` options, which will be passed to equivalent to
'git branch'. As a convenience, `--track` without `-b` implies branch +
creation; see the description of `--track` below. ------------
$ git checkout -b <branch> --track <remote>/<branch>
------------
+
You could omit <branch>, in which case the command degenerates to
"check out the current branch", which is a glorified no-op with a
rather expensive side-effects to show only the tracking information,
if exists, for the current branch.
'git checkout' -b|-B <new_branch> [<start point>]::
Specifying `-b` causes a new branch to be created as if
linkgit:git-branch[1] were called and then checked out. In
this case you can use the `--track` or `--no-track` options,
which will be passed to 'git branch'. As a convenience,
`--track` without `-b` implies branch creation; see the
description of `--track` below.
+ +
If `-B` is given, <new_branch> is created if it doesn't exist; otherwise, it If `-B` is given, <new_branch> is created if it doesn't exist; otherwise, it
is reset. This is the transactional equivalent of is reset. This is the transactional equivalent of
@ -45,6 +61,21 @@ $ git checkout <branch>
that is to say, the branch is not reset/created unless "git checkout" is that is to say, the branch is not reset/created unless "git checkout" is
successful. successful.
'git checkout' --detach [<branch>]::
'git checkout' <commit>::
Prepare to work on top of <commit>, by detaching HEAD at it
(see "DETACHED HEAD" section), and updating the index and the
files in the working tree. Local modifications to the files
in the working tree are kept, so that the resulting working
tree will be the state recorded in the commit plus the local
modifications.
+
Passing `--detach` forces this behavior in the case of a <branch> (without
the option, giving a branch name to the command would check out the branch,
instead of detaching HEAD at it), or the current commit,
if no <branch> is specified.
'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...:: 'git checkout' [-p|--patch] [<tree-ish>] [--] <pathspec>...::
When <paths> or `--patch` are given, 'git checkout' does *not* When <paths> or `--patch` are given, 'git checkout' does *not*