blob: 118d9d86f79427373eb92753abf7e134ed925fe8 [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 Hamanoc9cb5172018-06-01 07:13:4412'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 Hamanob9d9d902018-05-23 07:07:42104--rebase[=false|true|merges|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 Hamanob9d9d902018-05-23 07:07:42111When set to `merges`, rebase using `git rebase --rebase-merges` so that
112the local merge commits are included in the rebase (see
113linkgit:git-rebase[1] for details).
114+
Junio C Hamanoba423bd2015-03-28 18:18:17115When set to preserve, rebase with the `--preserve-merges` option passed
116to `git rebase` so that locally created merge commits will not be flattened.
Junio C Hamanocf4a1742013-09-11 22:57:50117+
118When false, merge the current branch into the upstream branch.
Junio C Hamano982eb112010-11-18 00:53:09119+
Junio C Hamano289d7e82016-01-27 00:20:38120When `interactive`, enable the interactive mode of rebase.
121+
Junio C Hamano322c6242015-03-23 21:32:46122See `pull.rebase`, `branch.<name>.rebase` and `branch.autoSetupRebase` in
Junio C Hamanoeef01fe2010-12-13 08:31:58123linkgit:git-config[1] if you want to make `git pull` always use
Junio C Hamanob76a6862012-05-02 22:02:46124`--rebase` instead of merging.
Junio C Hamano9c334152008-02-12 03:18:52125+
Junio C Hamano6fb124c2008-06-13 10:04:01126[NOTE]
127This is a potentially _dangerous_ mode of operation.
Junio C Hamano9c334152008-02-12 03:18:52128It rewrites history, which does not bode well when you
129published that history already. Do *not* use this option
130unless you have read linkgit:git-rebase[1] carefully.
Junio C Hamano0c999702007-12-03 09:57:55131
Junio C Hamanoeb415992008-06-08 22:49:47132--no-rebase::
133Override earlier --rebase.
Junio C Hamano0c999702007-12-03 09:57:55134
Junio C Hamano5996b672016-04-13 22:01:41135--autostash::
136--no-autostash::
137Before starting rebase, stash local modifications away (see
Junio C Hamano967cda72017-06-30 21:49:53138linkgit:git-stash[1]) if needed, and apply the stash entry when
Junio C Hamano5996b672016-04-13 22:01:41139done. `--no-autostash` is useful to override the `rebase.autoStash`
140configuration variable (see linkgit:git-config[1]).
141+
142This option is only valid when "--rebase" is used.
143
Junio C Hamanoc21ab052009-10-31 04:03:55144Options related to fetching
145~~~~~~~~~~~~~~~~~~~~~~~~~~~
146
Junio C Hamano6d559fc2008-02-20 10:44:26147include::fetch-options.txt[]
148
149include::pull-fetch-param.txt[]
150
151include::urls-remotes.txt[]
152
153include::merge-strategies.txt[]
154
Junio C Hamanod3339982007-02-09 08:38:48155DEFAULT BEHAVIOUR
156-----------------
157
158Often people use `git pull` without giving any parameter.
159Traditionally, this has been equivalent to saying `git pull
160origin`. However, when configuration `branch.<name>.remote` is
161present while on branch `<name>`, that value is used instead of
162`origin`.
163
164In order to determine what URL to use to fetch from, the value
165of the configuration `remote.<origin>.url` is consulted
Junio C Hamano7016b0b2017-06-05 02:16:19166and if there is not any such variable, the value on the `URL:` line
167in `$GIT_DIR/remotes/<origin>` is used.
Junio C Hamanod3339982007-02-09 08:38:48168
169In order to determine what remote branches to fetch (and
Junio C Hamano97bcb482010-11-25 03:16:07170optionally store in the remote-tracking branches) when the command is
Junio C Hamanod3339982007-02-09 08:38:48171run without any refspec parameters on the command line, values
172of the configuration variable `remote.<origin>.fetch` are
173consulted, and if there aren't any, `$GIT_DIR/remotes/<origin>`
Junio C Hamano7016b0b2017-06-05 02:16:19174is consulted and its `Pull:` lines are used.
Junio C Hamanod3339982007-02-09 08:38:48175In addition to the refspec formats described in the OPTIONS
176section, you can have a globbing refspec that looks like this:
177
178------------
179refs/heads/*:refs/remotes/origin/*
180------------
181
182A globbing refspec must have a non-empty RHS (i.e. must store
Junio C Hamano97bcb482010-11-25 03:16:07183what were fetched in remote-tracking branches), and its LHS and RHS
Junio C Hamanod3339982007-02-09 08:38:48184must end with `/*`. The above specifies that all remote
Junio C Hamano97bcb482010-11-25 03:16:07185branches are tracked using remote-tracking branches in
Junio C Hamanod3339982007-02-09 08:38:48186`refs/remotes/origin/` hierarchy under the same name.
187
188The rule to determine which remote branch to merge after
189fetching is a bit involved, in order not to break backward
190compatibility.
191
192If explicit refspecs were given on the command
193line of `git pull`, they are all merged.
194
195When no refspec was given on the command line, then `git pull`
196uses the refspec from the configuration or
197`$GIT_DIR/remotes/<origin>`. In such cases, the following
198rules apply:
199
200. If `branch.<name>.merge` configuration for the current
201 branch `<name>` exists, that is the name of the branch at the
202 remote site that is merged.
203
204. If the refspec is a globbing one, nothing is merged.
205
206. Otherwise the remote branch of the first refspec is merged.
207
208
Junio C Hamano1a4e8412005-12-27 08:17:23209EXAMPLES
210--------
211
Junio C Hamano6d76d612008-05-09 05:46:08212* Update the remote-tracking branches for the repository
213 you cloned from, then merge one of them into your
214 current branch:
215+
216------------------------------------------------
Junio C Hamano4c60d9a2017-05-04 14:36:22217$ git pull
218$ git pull origin
Junio C Hamano6d76d612008-05-09 05:46:08219------------------------------------------------
220+
221Normally the branch merged in is the HEAD of the remote repository,
222but the choice is determined by the branch.<name>.remote and
223branch.<name>.merge options; see linkgit:git-config[1] for details.
Junio C Hamano1a4e8412005-12-27 08:17:23224
Junio C Hamano6d76d612008-05-09 05:46:08225* Merge into the current branch the remote branch `next`:
226+
227------------------------------------------------
228$ git pull origin next
229------------------------------------------------
230+
231This leaves a copy of `next` temporarily in FETCH_HEAD, but
Junio C Hamanoc21ab052009-10-31 04:03:55232does not update any remote-tracking branches. Using remote-tracking
233branches, the same can be done by invoking fetch and merge:
Junio C Hamano6d76d612008-05-09 05:46:08234+
235------------------------------------------------
Junio C Hamanoc21ab052009-10-31 04:03:55236$ git fetch origin
237$ git merge origin/next
Junio C Hamano6d76d612008-05-09 05:46:08238------------------------------------------------
Junio C Hamano1a4e8412005-12-27 08:17:23239
240
Junio C Hamano09cfe6f2013-03-27 22:10:42241If you tried a pull which resulted in complex conflicts and
Junio C Hamano1aa40d22010-01-21 17:46:43242would want to start over, you can recover with 'git reset'.
Junio C Hamano1a4e8412005-12-27 08:17:23243
244
Junio C Hamano56ace3d2017-01-10 23:43:41245include::transfer-data-leaks.txt[]
246
Junio C Hamano5cd15182011-04-05 00:21:10247BUGS
248----
249Using --recurse-submodules can only fetch new commits in already checked
250out submodules right now. When e.g. upstream added a new submodule in the
251just fetched commits of the superproject the submodule itself can not be
252fetched, making it impossible to check out that submodule later without
Junio C Hamano076ffcc2013-02-06 05:13:21253having to do a fetch again. This is expected to be fixed in a future Git
Junio C Hamano5cd15182011-04-05 00:21:10254version.
255
Junio C Hamano1a4e8412005-12-27 08:17:23256SEE ALSO
257--------
Junio C Hamano35738e82008-01-07 07:55:46258linkgit:git-fetch[1], linkgit:git-merge[1], linkgit:git-config[1]
Junio C Hamano1a4e8412005-12-27 08:17:23259
Junio C Hamano1a4e8412005-12-27 08:17:23260GIT
261---
Junio C Hamanof7c042d2008-06-06 22:50:53262Part of the linkgit:git[1] suite