Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 1 | git-pull(1) |
| 2 | =========== |
| 3 | |
| 4 | NAME |
| 5 | ---- |
Junio C Hamano | 8401f14 | 2013-07-12 22:47:46 | [diff] [blame] | 6 | git-pull - Fetch from and integrate with another repository or a local branch |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 7 | |
| 8 | |
| 9 | SYNOPSIS |
| 10 | -------- |
Junio C Hamano | 15567bc | 2011-07-23 00:51:59 | [diff] [blame] | 11 | [verse] |
Junio C Hamano | b5a296f | 2010-08-13 02:46:36 | [diff] [blame] | 12 | 'git pull' [options] [<repository> [<refspec>...]] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 13 | |
| 14 | |
| 15 | DESCRIPTION |
| 16 | ----------- |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 17 | |
Junio C Hamano | b5a296f | 2010-08-13 02:46:36 | [diff] [blame] | 18 | Incorporates changes from a remote repository into the current |
| 19 | branch. In its default mode, `git pull` is shorthand for |
| 20 | `git fetch` followed by `git merge FETCH_HEAD`. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 21 | |
Junio C Hamano | b5a296f | 2010-08-13 02:46:36 | [diff] [blame] | 22 | More precisely, 'git pull' runs 'git fetch' with the given |
| 23 | parameters and calls 'git merge' to merge the retrieved branch |
| 24 | heads into the current branch. |
| 25 | With `--rebase`, it runs 'git rebase' instead of 'git merge'. |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 26 | |
Junio C Hamano | b5a296f | 2010-08-13 02:46:36 | [diff] [blame] | 27 | <repository> should be the name of a remote repository as |
| 28 | passed to linkgit:git-fetch[1]. <refspec> can name an |
| 29 | arbitrary remote ref (for example, the name of a tag) or even |
Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 30 | a collection of refs with corresponding remote-tracking branches |
Junio C Hamano | 2e6ded8 | 2010-12-05 06:20:48 | [diff] [blame] | 31 | (e.g., refs/heads/{asterisk}:refs/remotes/origin/{asterisk}), |
| 32 | but usually it is the name of a branch in the remote repository. |
Junio C Hamano | b5a296f | 2010-08-13 02:46:36 | [diff] [blame] | 33 | |
| 34 | Default values for <repository> and <branch> are read from the |
| 35 | "remote" and "merge" configuration for the current branch |
| 36 | as set by linkgit:git-branch[1] `--track`. |
| 37 | |
| 38 | Assume 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 Hamano | 92fb952 | 2013-11-06 23:55:19 | [diff] [blame] | 45 | ^ |
| 46 | origin/master in your repository |
Junio C Hamano | b5a296f | 2010-08-13 02:46:36 | [diff] [blame] | 47 | ------------ |
| 48 | |
| 49 | Then "`git pull`" will fetch and replay the changes from the remote |
| 50 | `master` branch since it diverged from the local `master` (i.e., `E`) |
| 51 | until its current commit (`C`) on top of `master` and record the |
| 52 | result in a new commit along with the names of the two parent commits |
| 53 | and a log message from the user describing the changes. |
| 54 | |
| 55 | ------------ |
Junio C Hamano | 92fb952 | 2013-11-06 23:55:19 | [diff] [blame] | 56 | A---B---C origin/master |
Junio C Hamano | b5a296f | 2010-08-13 02:46:36 | [diff] [blame] | 57 | / \ |
| 58 | D---E---F---G---H master |
| 59 | ------------ |
| 60 | |
| 61 | See linkgit:git-merge[1] for details, including how conflicts |
| 62 | are presented and handled. |
| 63 | |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 64 | In 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 Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 66 | with uncommitted changes is discouraged: while possible, it leaves you |
Junio C Hamano | b5a296f | 2010-08-13 02:46:36 | [diff] [blame] | 67 | in a state that may be hard to back out of in the case of a conflict. |
| 68 | |
| 69 | If any of the remote changes overlap with local uncommitted changes, |
Junio C Hamano | 4c60d9a | 2017-05-04 14:36:22 | [diff] [blame] | 70 | the merge will be automatically canceled and the work tree untouched. |
Junio C Hamano | b5a296f | 2010-08-13 02:46:36 | [diff] [blame] | 71 | It is generally best to get any local changes in working order before |
| 72 | pulling or stash them away with linkgit:git-stash[1]. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 73 | |
| 74 | OPTIONS |
| 75 | ------- |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 76 | |
Junio C Hamano | ea90ab3 | 2010-03-15 20:32:55 | [diff] [blame] | 77 | -q:: |
| 78 | --quiet:: |
| 79 | This is passed to both underlying git-fetch to squelch reporting of |
| 80 | during transfer, and underlying git-merge to squelch output during |
| 81 | merging. |
| 82 | |
| 83 | -v:: |
| 84 | --verbose:: |
| 85 | Pass --verbose to git-fetch and git-merge. |
| 86 | |
Junio C Hamano | 5cd1518 | 2011-04-05 00:21:10 | [diff] [blame] | 87 | --[no-]recurse-submodules[=yes|on-demand|no]:: |
Junio C Hamano | e611683 | 2011-02-08 00:49:45 | [diff] [blame] | 88 | This option controls if new commits of all populated submodules should |
Junio C Hamano | 1b61cf8 | 2017-07-13 23:40:39 | [diff] [blame] | 89 | be fetched and updated, too (see linkgit:git-config[1] and |
| 90 | linkgit:gitmodules[5]). |
| 91 | + |
| 92 | If the checkout is done via rebase, local submodule commits are rebased as well. |
| 93 | + |
| 94 | If the update is done via merge, the submodule conflicts are resolved and checked out. |
Junio C Hamano | e611683 | 2011-02-08 00:49:45 | [diff] [blame] | 95 | |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 96 | Options related to merging |
| 97 | ~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 98 | |
Junio C Hamano | f7bb669 | 2008-01-27 08:23:46 | [diff] [blame] | 99 | :git-pull: 1 |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 100 | |
Junio C Hamano | c5bd79e | 2014-01-27 21:31:26 | [diff] [blame] | 101 | include::merge-options.txt[] |
| 102 | |
Junio C Hamano | d031611 | 2012-08-22 19:55:29 | [diff] [blame] | 103 | -r:: |
Junio C Hamano | 289d7e8 | 2016-01-27 00:20:38 | [diff] [blame] | 104 | --rebase[=false|true|preserve|interactive]:: |
Junio C Hamano | cf4a174 | 2013-09-11 22:57:50 | [diff] [blame] | 105 | When true, rebase the current branch on top of the upstream |
| 106 | branch after fetching. If there is a remote-tracking branch |
| 107 | corresponding to the upstream branch and the upstream branch |
| 108 | was rebased since last fetched, the rebase uses that information |
| 109 | to avoid rebasing non-local changes. |
| 110 | + |
Junio C Hamano | ba423bd | 2015-03-28 18:18:17 | [diff] [blame] | 111 | When set to preserve, rebase with the `--preserve-merges` option passed |
| 112 | to `git rebase` so that locally created merge commits will not be flattened. |
Junio C Hamano | cf4a174 | 2013-09-11 22:57:50 | [diff] [blame] | 113 | + |
| 114 | When false, merge the current branch into the upstream branch. |
Junio C Hamano | 982eb11 | 2010-11-18 00:53:09 | [diff] [blame] | 115 | + |
Junio C Hamano | 289d7e8 | 2016-01-27 00:20:38 | [diff] [blame] | 116 | When `interactive`, enable the interactive mode of rebase. |
| 117 | + |
Junio C Hamano | 322c624 | 2015-03-23 21:32:46 | [diff] [blame] | 118 | See `pull.rebase`, `branch.<name>.rebase` and `branch.autoSetupRebase` in |
Junio C Hamano | eef01fe | 2010-12-13 08:31:58 | [diff] [blame] | 119 | linkgit:git-config[1] if you want to make `git pull` always use |
Junio C Hamano | b76a686 | 2012-05-02 22:02:46 | [diff] [blame] | 120 | `--rebase` instead of merging. |
Junio C Hamano | 9c33415 | 2008-02-12 03:18:52 | [diff] [blame] | 121 | + |
Junio C Hamano | 6fb124c | 2008-06-13 10:04:01 | [diff] [blame] | 122 | [NOTE] |
| 123 | This is a potentially _dangerous_ mode of operation. |
Junio C Hamano | 9c33415 | 2008-02-12 03:18:52 | [diff] [blame] | 124 | It rewrites history, which does not bode well when you |
| 125 | published that history already. Do *not* use this option |
| 126 | unless you have read linkgit:git-rebase[1] carefully. |
Junio C Hamano | 0c99970 | 2007-12-03 09:57:55 | [diff] [blame] | 127 | |
Junio C Hamano | eb41599 | 2008-06-08 22:49:47 | [diff] [blame] | 128 | --no-rebase:: |
| 129 | Override earlier --rebase. |
Junio C Hamano | 0c99970 | 2007-12-03 09:57:55 | [diff] [blame] | 130 | |
Junio C Hamano | 5996b67 | 2016-04-13 22:01:41 | [diff] [blame] | 131 | --autostash:: |
| 132 | --no-autostash:: |
| 133 | Before starting rebase, stash local modifications away (see |
Junio C Hamano | 967cda7 | 2017-06-30 21:49:53 | [diff] [blame] | 134 | linkgit:git-stash[1]) if needed, and apply the stash entry when |
Junio C Hamano | 5996b67 | 2016-04-13 22:01:41 | [diff] [blame] | 135 | done. `--no-autostash` is useful to override the `rebase.autoStash` |
| 136 | configuration variable (see linkgit:git-config[1]). |
| 137 | + |
| 138 | This option is only valid when "--rebase" is used. |
| 139 | |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 140 | Options related to fetching |
| 141 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 142 | |
Junio C Hamano | 6d559fc | 2008-02-20 10:44:26 | [diff] [blame] | 143 | include::fetch-options.txt[] |
| 144 | |
| 145 | include::pull-fetch-param.txt[] |
| 146 | |
| 147 | include::urls-remotes.txt[] |
| 148 | |
| 149 | include::merge-strategies.txt[] |
| 150 | |
Junio C Hamano | d333998 | 2007-02-09 08:38:48 | [diff] [blame] | 151 | DEFAULT BEHAVIOUR |
| 152 | ----------------- |
| 153 | |
| 154 | Often people use `git pull` without giving any parameter. |
| 155 | Traditionally, this has been equivalent to saying `git pull |
| 156 | origin`. However, when configuration `branch.<name>.remote` is |
| 157 | present while on branch `<name>`, that value is used instead of |
| 158 | `origin`. |
| 159 | |
| 160 | In order to determine what URL to use to fetch from, the value |
| 161 | of the configuration `remote.<origin>.url` is consulted |
Junio C Hamano | 7016b0b | 2017-06-05 02:16:19 | [diff] [blame] | 162 | and if there is not any such variable, the value on the `URL:` line |
| 163 | in `$GIT_DIR/remotes/<origin>` is used. |
Junio C Hamano | d333998 | 2007-02-09 08:38:48 | [diff] [blame] | 164 | |
| 165 | In order to determine what remote branches to fetch (and |
Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 166 | optionally store in the remote-tracking branches) when the command is |
Junio C Hamano | d333998 | 2007-02-09 08:38:48 | [diff] [blame] | 167 | run without any refspec parameters on the command line, values |
| 168 | of the configuration variable `remote.<origin>.fetch` are |
| 169 | consulted, and if there aren't any, `$GIT_DIR/remotes/<origin>` |
Junio C Hamano | 7016b0b | 2017-06-05 02:16:19 | [diff] [blame] | 170 | is consulted and its `Pull:` lines are used. |
Junio C Hamano | d333998 | 2007-02-09 08:38:48 | [diff] [blame] | 171 | In addition to the refspec formats described in the OPTIONS |
| 172 | section, you can have a globbing refspec that looks like this: |
| 173 | |
| 174 | ------------ |
| 175 | refs/heads/*:refs/remotes/origin/* |
| 176 | ------------ |
| 177 | |
| 178 | A globbing refspec must have a non-empty RHS (i.e. must store |
Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 179 | what were fetched in remote-tracking branches), and its LHS and RHS |
Junio C Hamano | d333998 | 2007-02-09 08:38:48 | [diff] [blame] | 180 | must end with `/*`. The above specifies that all remote |
Junio C Hamano | 97bcb48 | 2010-11-25 03:16:07 | [diff] [blame] | 181 | branches are tracked using remote-tracking branches in |
Junio C Hamano | d333998 | 2007-02-09 08:38:48 | [diff] [blame] | 182 | `refs/remotes/origin/` hierarchy under the same name. |
| 183 | |
| 184 | The rule to determine which remote branch to merge after |
| 185 | fetching is a bit involved, in order not to break backward |
| 186 | compatibility. |
| 187 | |
| 188 | If explicit refspecs were given on the command |
| 189 | line of `git pull`, they are all merged. |
| 190 | |
| 191 | When no refspec was given on the command line, then `git pull` |
| 192 | uses the refspec from the configuration or |
| 193 | `$GIT_DIR/remotes/<origin>`. In such cases, the following |
| 194 | rules 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 Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 205 | EXAMPLES |
| 206 | -------- |
| 207 | |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 208 | * 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 Hamano | 4c60d9a | 2017-05-04 14:36:22 | [diff] [blame] | 213 | $ git pull |
| 214 | $ git pull origin |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 215 | ------------------------------------------------ |
| 216 | + |
| 217 | Normally the branch merged in is the HEAD of the remote repository, |
| 218 | but the choice is determined by the branch.<name>.remote and |
| 219 | branch.<name>.merge options; see linkgit:git-config[1] for details. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 220 | |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 221 | * Merge into the current branch the remote branch `next`: |
| 222 | + |
| 223 | ------------------------------------------------ |
| 224 | $ git pull origin next |
| 225 | ------------------------------------------------ |
| 226 | + |
| 227 | This leaves a copy of `next` temporarily in FETCH_HEAD, but |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 228 | does not update any remote-tracking branches. Using remote-tracking |
| 229 | branches, the same can be done by invoking fetch and merge: |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 230 | + |
| 231 | ------------------------------------------------ |
Junio C Hamano | c21ab05 | 2009-10-31 04:03:55 | [diff] [blame] | 232 | $ git fetch origin |
| 233 | $ git merge origin/next |
Junio C Hamano | 6d76d61 | 2008-05-09 05:46:08 | [diff] [blame] | 234 | ------------------------------------------------ |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 235 | |
| 236 | |
Junio C Hamano | 09cfe6f | 2013-03-27 22:10:42 | [diff] [blame] | 237 | If you tried a pull which resulted in complex conflicts and |
Junio C Hamano | 1aa40d2 | 2010-01-21 17:46:43 | [diff] [blame] | 238 | would want to start over, you can recover with 'git reset'. |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 239 | |
| 240 | |
Junio C Hamano | 56ace3d | 2017-01-10 23:43:41 | [diff] [blame] | 241 | include::transfer-data-leaks.txt[] |
| 242 | |
Junio C Hamano | 5cd1518 | 2011-04-05 00:21:10 | [diff] [blame] | 243 | BUGS |
| 244 | ---- |
| 245 | Using --recurse-submodules can only fetch new commits in already checked |
| 246 | out submodules right now. When e.g. upstream added a new submodule in the |
| 247 | just fetched commits of the superproject the submodule itself can not be |
| 248 | fetched, making it impossible to check out that submodule later without |
Junio C Hamano | 076ffcc | 2013-02-06 05:13:21 | [diff] [blame] | 249 | having to do a fetch again. This is expected to be fixed in a future Git |
Junio C Hamano | 5cd1518 | 2011-04-05 00:21:10 | [diff] [blame] | 250 | version. |
| 251 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 252 | SEE ALSO |
| 253 | -------- |
Junio C Hamano | 35738e8 | 2008-01-07 07:55:46 | [diff] [blame] | 254 | linkgit:git-fetch[1], linkgit:git-merge[1], linkgit:git-config[1] |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 255 | |
Junio C Hamano | 1a4e841 | 2005-12-27 08:17:23 | [diff] [blame] | 256 | GIT |
| 257 | --- |
Junio C Hamano | f7c042d | 2008-06-06 22:50:53 | [diff] [blame] | 258 | Part of the linkgit:git[1] suite |