Documentation: a few spelling fixes
[git/git.git] / Documentation / git-checkout.txt
CommitLineData
215a7ad1
JH
1git-checkout(1)
2===============
7fc9d69f
JH
3
4NAME
5----
7bd7f280 6git-checkout - Checkout and switch to a branch
7fc9d69f
JH
7
8SYNOPSIS
9--------
71bb1033 10[verse]
969d326d 11'git-checkout' [-f] [-b <new_branch> [-l]] [-m] [<branch>]
71bb1033 12'git-checkout' [-m] [<branch>] <paths>...
7fc9d69f
JH
13
14DESCRIPTION
15-----------
4aaa7027 16
71bb1033 17When <paths> are not given, this command switches branches by
4aaa7027
JH
18updating the index and working tree to reflect the specified
19branch, <branch>, and updating HEAD to be <branch> or, if
71bb1033
JL
20specified, <new_branch>. Using -b will cause <new_branch> to
21be created.
4aaa7027
JH
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
7fc9d69f
JH
31
32OPTIONS
33-------
0270f7c5 34-f::
71bb1033 35 Force a re-read of everything.
0270f7c5
LAS
36
37-b::
2b1f4247
SP
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.
7fc9d69f 42
969d326d
SP
43-l::
44 Create the new branch's ref log. This activates recording of
45 all changes to made the branch ref, enabling use of date
46 based sha1 expressions such as "<branchname>@{yesterday}".
47
1be0659e 48-m::
71bb1033
JL
49 If you have local modifications to one or more files that
50 are different between the current branch and the branch to
51 which you are switching, the command refuses to switch
52 branches in order to preserve your modifications in context.
53 However, with this option, a three-way merge between the current
1be0659e
JH
54 branch, your working tree contents, and the new branch
55 is done, and you will be on the new branch.
56+
57When a merge conflict happens, the index entries for conflicting
58paths are left unmerged, and you need to resolve the conflicts
59and mark the resolved paths with `git update-index`.
60
0270f7c5
LAS
61<new_branch>::
62 Name for the new branch.
7fc9d69f 63
0270f7c5
LAS
64<branch>::
65 Branch to checkout; may be any object ID that resolves to a
66 commit. Defaults to HEAD.
7fc9d69f 67
4aaa7027 68
1be0659e
JH
69EXAMPLES
70--------
4aaa7027 71
1be0659e 72. The following sequence checks out the `master` branch, reverts
4aaa7027
JH
73the `Makefile` to two revisions back, deletes hello.c by
74mistake, and gets it back from the index.
1be0659e 75+
4aaa7027 76------------
48aeecdc
SE
77$ git checkout master <1>
78$ git checkout master~2 Makefile <2>
4aaa7027 79$ rm -f hello.c
48aeecdc
SE
80$ git checkout hello.c <3>
81------------
82+
1e2ccd3a
JH
83<1> switch branch
84<2> take out a file out of other commit
48aeecdc 85<3> restore hello.c from HEAD of current branch
1be0659e 86+
48aeecdc
SE
87If you have an unfortunate branch that is named `hello.c`, this
88step would be confused as an instruction to switch to that branch.
89You should instead write:
1be0659e 90+
4aaa7027
JH
91------------
92$ git checkout -- hello.c
93------------
94
1be0659e 95. After working in a wrong branch, switching to the correct
71bb1033 96branch would be done using:
1be0659e
JH
97+
98------------
99$ git checkout mytopic
100------------
101+
102However, your "wrong" branch and correct "mytopic" branch may
103differ in files that you have locally modified, in which case,
104the above checkout would fail like this:
105+
106------------
107$ git checkout mytopic
108fatal: Entry 'frotz' not uptodate. Cannot merge.
109------------
110+
111You can give the `-m` flag to the command, which would try a
112three-way merge:
113+
114------------
115$ git checkout -m mytopic
116Auto-merging frotz
117------------
118+
119After this three-way merge, the local modifications are _not_
120registered in your index file, so `git diff` would show you what
121changes you made since the tip of the new branch.
122
123. When a merge conflict happens during switching branches with
124the `-m` option, you would see something like this:
125+
126------------
127$ git checkout -m mytopic
128Auto-merging frotz
129merge: warning: conflicts during merge
130ERROR: Merge conflict in frotz
131fatal: merge program failed
132------------
133+
134At this point, `git diff` shows the changes cleanly merged as in
135the previous example, as well as the changes in the conflicted
136files. Edit and resolve the conflict and mark it resolved with
137`git update-index` as usual:
138+
139------------
140$ edit frotz
141$ git update-index frotz
142------------
143
4aaa7027 144
7fc9d69f
JH
145Author
146------
147Written by Linus Torvalds <torvalds@osdl.org>
148
149Documentation
150--------------
151Documentation by Junio C Hamano and the git-list <git@vger.kernel.org>.
152
153GIT
154---
a7154e91 155Part of the gitlink:git[7] suite
7fc9d69f 156