Documentation / git-checkout.txton commit Merge branch 'lt/dirwalk' (376bb3a)
   1git-checkout(1)
   2===============
   3
   4NAME
   5----
   6git-checkout - Checkout and switch to a branch
   7
   8SYNOPSIS
   9--------
  10[verse]
  11'git-checkout' [-f] [-b <new_branch>] [-m] [<branch>]
  12'git-checkout' [-m] [<branch>] <paths>...
  13
  14DESCRIPTION
  15-----------
  16
  17When <paths> are not given, this command switches branches by
  18updating the index and working tree to reflect the specified
  19branch, <branch>, and updating HEAD to be <branch> or, if
  20specified, <new_branch>.  Using -b will cause <new_branch> to
  21be created.
  22
  23When <paths> are given, this command does *not* switch
  24branches.  It updates the named paths in the working tree from
  25the index file (i.e. it runs `git-checkout-index -f -u`).  In
  26this case, `-f` and `-b` options are meaningless and giving
  27either of them results in an error.  <branch> argument can be
  28used to specify a specific tree-ish to update the index for the
  29given paths before updating the working tree.
  30
  31
  32OPTIONS
  33-------
  34-f::
  35        Force a re-read of everything.
  36
  37-b::
  38        Create a new branch named <new_branch> and start it at
  39        <branch>.  The new branch name must pass all checks defined
  40        by gitlink:git-check-ref-format[1].  Some of these checks
  41        may restrict the characters allowed in a branch name.
  42
  43-m::
  44        If you have local modifications to one or more files that
  45        are different between the current branch and the branch to
  46        which you are switching, the command refuses to switch
  47        branches in order to preserve your modifications in context.
  48        However, with this option, a three-way merge between the current
  49        branch, your working tree contents, and the new branch
  50        is done, and you will be on the new branch.
  51+
  52When a merge conflict happens, the index entries for conflicting
  53paths are left unmerged, and you need to resolve the conflicts
  54and mark the resolved paths with `git update-index`.
  55
  56<new_branch>::
  57        Name for the new branch.
  58
  59<branch>::
  60        Branch to checkout; may be any object ID that resolves to a
  61        commit. Defaults to HEAD.
  62
  63
  64EXAMPLES
  65--------
  66
  67. The following sequence checks out the `master` branch, reverts
  68the `Makefile` to two revisions back, deletes hello.c by
  69mistake, and gets it back from the index.
  70+
  71------------
  72$ git checkout master             <1>
  73$ git checkout master~2 Makefile  <2>
  74$ rm -f hello.c
  75$ git checkout hello.c            <3>
  76------------
  77+
  78<1> switch branch
  79<2> take out a file out of other commit
  80<3> restore hello.c from HEAD of current branch
  81+
  82If you have an unfortunate branch that is named `hello.c`, this
  83step would be confused as an instruction to switch to that branch.
  84You should instead write:
  85+
  86------------
  87$ git checkout -- hello.c
  88------------
  89
  90. After working in a wrong branch, switching to the correct
  91branch would be done using:
  92+
  93------------
  94$ git checkout mytopic
  95------------
  96+
  97However, your "wrong" branch and correct "mytopic" branch may
  98differ in files that you have locally modified, in which case,
  99the above checkout would fail like this:
 100+
 101------------
 102$ git checkout mytopic
 103fatal: Entry 'frotz' not uptodate. Cannot merge.
 104------------
 105+
 106You can give the `-m` flag to the command, which would try a
 107three-way merge:
 108+
 109------------
 110$ git checkout -m mytopic
 111Auto-merging frotz
 112------------
 113+
 114After this three-way merge, the local modifications are _not_
 115registered in your index file, so `git diff` would show you what
 116changes you made since the tip of the new branch.
 117
 118. When a merge conflict happens during switching branches with
 119the `-m` option, you would see something like this:
 120+
 121------------
 122$ git checkout -m mytopic
 123Auto-merging frotz
 124merge: warning: conflicts during merge
 125ERROR: Merge conflict in frotz
 126fatal: merge program failed
 127------------
 128+
 129At this point, `git diff` shows the changes cleanly merged as in
 130the previous example, as well as the changes in the conflicted
 131files.  Edit and resolve the conflict and mark it resolved with
 132`git update-index` as usual:
 133+
 134------------
 135$ edit frotz
 136$ git update-index frotz
 137------------
 138
 139
 140Author
 141------
 142Written by Linus Torvalds <torvalds@osdl.org>
 143
 144Documentation
 145--------------
 146Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
 147
 148GIT
 149---
 150Part of the gitlink:git[7] suite
 151