blob: ce05b7a5b13eadb6870f16a7168559434d376c20 [file] [log] [blame]
Junio C Hamano1a4e8412005-12-27 08:17:231git-pull(1)
2===========
3
4NAME
5----
Junio C Hamano8401f142013-07-12 22:47:466git-pull - Fetch from and integrate with another repository or a local branch
Junio C Hamano1a4e8412005-12-27 08:17:237
8
9SYNOPSIS
10--------
Junio C Hamano15567bc2011-07-23 00:51:5911[verse]
Junio C Hamanob5a296f2010-08-13 02:46:3612'git pull' [options] [<repository> [<refspec>...]]
Junio C Hamano1a4e8412005-12-27 08:17:2313
14
15DESCRIPTION
16-----------
Junio C Hamano1a4e8412005-12-27 08:17:2317
Junio C Hamanob5a296f2010-08-13 02:46:3618Incorporates changes from a remote repository into the current
19branch. In its default mode, `git pull` is shorthand for
20`git fetch` followed by `git merge FETCH_HEAD`.
Junio C Hamano1a4e8412005-12-27 08:17:2321
Junio C Hamanob5a296f2010-08-13 02:46:3622More precisely, 'git pull' runs 'git fetch' with the given
23parameters and calls 'git merge' to merge the retrieved branch
24heads into the current branch.
25With `--rebase`, it runs 'git rebase' instead of 'git merge'.
Junio C Hamano1aa40d22010-01-21 17:46:4326
Junio C Hamanob5a296f2010-08-13 02:46:3627<repository> should be the name of a remote repository as
28passed to linkgit:git-fetch[1]. <refspec> can name an
29arbitrary remote ref (for example, the name of a tag) or even
Junio C Hamano97bcb482010-11-25 03:16:0730a collection of refs with corresponding remote-tracking branches
Junio C Hamano2e6ded82010-12-05 06:20:4831(e.g., refs/heads/{asterisk}:refs/remotes/origin/{asterisk}),
32but usually it is the name of a branch in the remote repository.
Junio C Hamanob5a296f2010-08-13 02:46:3633
34Default values for <repository> and <branch> are read from the
35"remote" and "merge" configuration for the current branch
36as set by linkgit:git-branch[1] `--track`.
37
38Assume the following history exists and the current branch is
39"`master`":
40
41------------
42 A---B---C master on origin
43 /
44 D---E---F---G master
Junio C Hamano92fb9522013-11-06 23:55:1945^
46origin/master in your repository
Junio C Hamanob5a296f2010-08-13 02:46:3647------------
48
49Then "`git pull`" will fetch and replay the changes from the remote
50`master` branch since it diverged from the local `master` (i.e., `E`)
51until its current commit (`C`) on top of `master` and record the
52result in a new commit along with the names of the two parent commits
53and a log message from the user describing the changes.
54
55------------
Junio C Hamano92fb9522013-11-06 23:55:1956 A---B---C origin/master
Junio C Hamanob5a296f2010-08-13 02:46:3657 / \
58 D---E---F---G---H master
59------------
60
61See linkgit:git-merge[1] for details, including how conflicts
62are presented and handled.
63
Junio C Hamano076ffcc2013-02-06 05:13:2164In Git 1.7.0 or later, to cancel a conflicting merge, use
65`git reset --merge`. *Warning*: In older versions of Git, running 'git pull'
Junio C Hamano1aa40d22010-01-21 17:46:4366with uncommitted changes is discouraged: while possible, it leaves you
Junio C Hamanob5a296f2010-08-13 02:46:3667in a state that may be hard to back out of in the case of a conflict.
68
69If any of the remote changes overlap with local uncommitted changes,
Junio C Hamano4c60d9a2017-05-04 14:36:2270the merge will be automatically canceled and the work tree untouched.
Junio C Hamanob5a296f2010-08-13 02:46:3671It is generally best to get any local changes in working order before
72pulling or stash them away with linkgit:git-stash[1].
Junio C Hamano1a4e8412005-12-27 08:17:2373
74OPTIONS
75-------
Junio C Hamanoc21ab052009-10-31 04:03:5576
Junio C Hamanoea90ab32010-03-15 20:32:5577-q::
78--quiet::
79This is passed to both underlying git-fetch to squelch reporting of
80during transfer, and underlying git-merge to squelch output during
81merging.
82
83-v::
84--verbose::
85Pass --verbose to git-fetch and git-merge.
86
Junio C Hamano5cd15182011-04-05 00:21:1087--[no-]recurse-submodules[=yes|on-demand|no]::
Junio C Hamanoe6116832011-02-08 00:49:4588This option controls if new commits of all populated submodules should
Junio C Hamano1b61cf82017-07-13 23:40:3989be fetched and updated, too (see linkgit:git-config[1] and
90linkgit:gitmodules[5]).
91+
92If the checkout is done via rebase, local submodule commits are rebased as well.
93+
94If the update is done via merge, the submodule conflicts are resolved and checked out.
Junio C Hamanoe6116832011-02-08 00:49:4595
Junio C Hamanoc21ab052009-10-31 04:03:5596Options related to merging
97~~~~~~~~~~~~~~~~~~~~~~~~~~
98
Junio C Hamanof7bb6692008-01-27 08:23:4699:git-pull: 1
Junio C Hamano1a4e8412005-12-27 08:17:23100
Junio C Hamanoc5bd79e2014-01-27 21:31:26101include::merge-options.txt[]
102
Junio C Hamanod0316112012-08-22 19:55:29103-r::
Junio C Hamano289d7e82016-01-27 00:20:38104--rebase[=false|true|preserve|interactive]::
Junio C Hamanocf4a1742013-09-11 22:57:50105When true, rebase the current branch on top of the upstream
106branch after fetching. If there is a remote-tracking branch
107corresponding to the upstream branch and the upstream branch
108was rebased since last fetched, the rebase uses that information
109to avoid rebasing non-local changes.
110+
Junio C Hamanoba423bd2015-03-28 18:18:17111When set to preserve, rebase with the `--preserve-merges` option passed
112to `git rebase` so that locally created merge commits will not be flattened.
Junio C Hamanocf4a1742013-09-11 22:57:50113+
114When false, merge the current branch into the upstream branch.
Junio C Hamano982eb112010-11-18 00:53:09115+
Junio C Hamano289d7e82016-01-27 00:20:38116When `interactive`, enable the interactive mode of rebase.
117+
Junio C Hamano322c6242015-03-23 21:32:46118See `pull.rebase`, `branch.<name>.rebase` and `branch.autoSetupRebase` in
Junio C Hamanoeef01fe2010-12-13 08:31:58119linkgit:git-config[1] if you want to make `git pull` always use
Junio C Hamanob76a6862012-05-02 22:02:46120`--rebase` instead of merging.
Junio C Hamano9c334152008-02-12 03:18:52121+
Junio C Hamano6fb124c2008-06-13 10:04:01122[NOTE]
123This is a potentially _dangerous_ mode of operation.
Junio C Hamano9c334152008-02-12 03:18:52124It rewrites history, which does not bode well when you
125published that history already. Do *not* use this option
126unless you have read linkgit:git-rebase[1] carefully.
Junio C Hamano0c999702007-12-03 09:57:55127
Junio C Hamanoeb415992008-06-08 22:49:47128--no-rebase::
129Override earlier --rebase.
Junio C Hamano0c999702007-12-03 09:57:55130
Junio C Hamano5996b672016-04-13 22:01:41131--autostash::
132--no-autostash::
133Before starting rebase, stash local modifications away (see
Junio C Hamano967cda72017-06-30 21:49:53134linkgit:git-stash[1]) if needed, and apply the stash entry when
Junio C Hamano5996b672016-04-13 22:01:41135done. `--no-autostash` is useful to override the `rebase.autoStash`
136configuration variable (see linkgit:git-config[1]).
137+
138This option is only valid when "--rebase" is used.
139
Junio C Hamanoc21ab052009-10-31 04:03:55140Options related to fetching
141~~~~~~~~~~~~~~~~~~~~~~~~~~~
142
Junio C Hamano6d559fc2008-02-20 10:44:26143include::fetch-options.txt[]
144
145include::pull-fetch-param.txt[]
146
147include::urls-remotes.txt[]
148
149include::merge-strategies.txt[]
150
Junio C Hamanod3339982007-02-09 08:38:48151DEFAULT BEHAVIOUR
152-----------------
153
154Often people use `git pull` without giving any parameter.
155Traditionally, this has been equivalent to saying `git pull
156origin`. However, when configuration `branch.<name>.remote` is
157present while on branch `<name>`, that value is used instead of
158`origin`.
159
160In order to determine what URL to use to fetch from, the value
161of the configuration `remote.<origin>.url` is consulted
Junio C Hamano7016b0b2017-06-05 02:16:19162and if there is not any such variable, the value on the `URL:` line
163in `$GIT_DIR/remotes/<origin>` is used.
Junio C Hamanod3339982007-02-09 08:38:48164
165In order to determine what remote branches to fetch (and
Junio C Hamano97bcb482010-11-25 03:16:07166optionally store in the remote-tracking branches) when the command is
Junio C Hamanod3339982007-02-09 08:38:48167run without any refspec parameters on the command line, values
168of the configuration variable `remote.<origin>.fetch` are
169consulted, and if there aren't any, `$GIT_DIR/remotes/<origin>`
Junio C Hamano7016b0b2017-06-05 02:16:19170is consulted and its `Pull:` lines are used.
Junio C Hamanod3339982007-02-09 08:38:48171In addition to the refspec formats described in the OPTIONS
172section, you can have a globbing refspec that looks like this:
173
174------------
175refs/heads/*:refs/remotes/origin/*
176------------
177
178A globbing refspec must have a non-empty RHS (i.e. must store
Junio C Hamano97bcb482010-11-25 03:16:07179what were fetched in remote-tracking branches), and its LHS and RHS
Junio C Hamanod3339982007-02-09 08:38:48180must end with `/*`. The above specifies that all remote
Junio C Hamano97bcb482010-11-25 03:16:07181branches are tracked using remote-tracking branches in
Junio C Hamanod3339982007-02-09 08:38:48182`refs/remotes/origin/` hierarchy under the same name.
183
184The rule to determine which remote branch to merge after
185fetching is a bit involved, in order not to break backward
186compatibility.
187
188If explicit refspecs were given on the command
189line of `git pull`, they are all merged.
190
191When no refspec was given on the command line, then `git pull`
192uses the refspec from the configuration or
193`$GIT_DIR/remotes/<origin>`. In such cases, the following
194rules apply:
195
196. If `branch.<name>.merge` configuration for the current
197 branch `<name>` exists, that is the name of the branch at the
198 remote site that is merged.
199
200. If the refspec is a globbing one, nothing is merged.
201
202. Otherwise the remote branch of the first refspec is merged.
203
204
Junio C Hamano1a4e8412005-12-27 08:17:23205EXAMPLES
206--------
207
Junio C Hamano6d76d612008-05-09 05:46:08208* Update the remote-tracking branches for the repository
209 you cloned from, then merge one of them into your
210 current branch:
211+
212------------------------------------------------
Junio C Hamano4c60d9a2017-05-04 14:36:22213$ git pull
214$ git pull origin
Junio C Hamano6d76d612008-05-09 05:46:08215------------------------------------------------
216+
217Normally the branch merged in is the HEAD of the remote repository,
218but the choice is determined by the branch.<name>.remote and
219branch.<name>.merge options; see linkgit:git-config[1] for details.
Junio C Hamano1a4e8412005-12-27 08:17:23220
Junio C Hamano6d76d612008-05-09 05:46:08221* Merge into the current branch the remote branch `next`:
222+
223------------------------------------------------
224$ git pull origin next
225------------------------------------------------
226+
227This leaves a copy of `next` temporarily in FETCH_HEAD, but
Junio C Hamanoc21ab052009-10-31 04:03:55228does not update any remote-tracking branches. Using remote-tracking
229branches, the same can be done by invoking fetch and merge:
Junio C Hamano6d76d612008-05-09 05:46:08230+
231------------------------------------------------
Junio C Hamanoc21ab052009-10-31 04:03:55232$ git fetch origin
233$ git merge origin/next
Junio C Hamano6d76d612008-05-09 05:46:08234------------------------------------------------
Junio C Hamano1a4e8412005-12-27 08:17:23235
236
Junio C Hamano09cfe6f2013-03-27 22:10:42237If you tried a pull which resulted in complex conflicts and
Junio C Hamano1aa40d22010-01-21 17:46:43238would want to start over, you can recover with 'git reset'.
Junio C Hamano1a4e8412005-12-27 08:17:23239
240
Junio C Hamano56ace3d2017-01-10 23:43:41241include::transfer-data-leaks.txt[]
242
Junio C Hamano5cd15182011-04-05 00:21:10243BUGS
244----
245Using --recurse-submodules can only fetch new commits in already checked
246out submodules right now. When e.g. upstream added a new submodule in the
247just fetched commits of the superproject the submodule itself can not be
248fetched, making it impossible to check out that submodule later without
Junio C Hamano076ffcc2013-02-06 05:13:21249having to do a fetch again. This is expected to be fixed in a future Git
Junio C Hamano5cd15182011-04-05 00:21:10250version.
251
Junio C Hamano1a4e8412005-12-27 08:17:23252SEE ALSO
253--------
Junio C Hamano35738e82008-01-07 07:55:46254linkgit:git-fetch[1], linkgit:git-merge[1], linkgit:git-config[1]
Junio C Hamano1a4e8412005-12-27 08:17:23255
Junio C Hamano1a4e8412005-12-27 08:17:23256GIT
257---
Junio C Hamanof7c042d2008-06-06 22:50:53258Part of the linkgit:git[1] suite