Autogenerated HTML docs for 58e3fb40f7ca1c28f9105c15166884f80bb22e55
[git.git] / git-checkout.txt
1 git-checkout(1)
2 ===============
3
4 NAME
5 ----
6 git-checkout - Checkout and switch to a branch.
7
8 SYNOPSIS
9 --------
10 'git-checkout' [-f] [-b <new_branch>] [<branch>] [<paths>...]
11
12 DESCRIPTION
13 -----------
14
15 When <paths> are not given, this command switches branches, by
16 updating the index and working tree to reflect the specified
17 branch, <branch>, and updating HEAD to be <branch> or, if
18 specified, <new_branch>.
19
20 When <paths> are given, this command does *not* switch
21 branches.  It updates the named paths in the working tree from
22 the index file (i.e. it runs `git-checkout-index -f -u`).  In
23 this case, `-f` and `-b` options are meaningless and giving
24 either of them results in an error.  <branch> argument can be
25 used to specify a specific tree-ish to update the index for the
26 given paths before updating the working tree.
27
28
29 OPTIONS
30 -------
31 -f::
32         Force an re-read of everything.
33
34 -b::
35         Create a new branch and start it at <branch>.
36
37 <new_branch>::
38         Name for the new branch.
39
40 <branch>::
41         Branch to checkout; may be any object ID that resolves to a
42         commit. Defaults to HEAD.
43
44
45 EXAMPLE
46 -------
47
48 The following sequence checks out the `master` branch, reverts
49 the `Makefile` to two revisions back, deletes hello.c by
50 mistake, and gets it back from the index.
51
52 ------------
53 $ git checkout master <1>
54 $ git checkout master~2 Makefile <2>
55 $ rm -f hello.c
56 $ git checkout hello.c <3>
57
58 <1> switch branch
59 <2> take out a file out of other commit
60 <3> or "git checkout -- hello.c", as in the next example.
61 ------------
62
63 If you have an unfortunate branch that is named `hello.c`, the
64 last step above would be confused as an instruction to switch to
65 that branch.  You should instead write:
66
67 ------------
68 $ git checkout -- hello.c
69 ------------
70
71
72 Author
73 ------
74 Written by Linus Torvalds <torvalds@osdl.org>
75
76 Documentation
77 --------------
78 Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
79
80 GIT
81 ---
82 Part of the gitlink:git[7] suite
83