1GIT-FETCH(1) Git Manual GIT-FETCH(1)
2
3
4
6 git-fetch - Download objects and refs from another repository
7
9 git fetch [<options>] [<repository> [<refspec>...]]
10
11 git fetch [<options>] <group>
12
13 git fetch --multiple [<options>] [(<repository> | <group>)...]
14
15 git fetch --all [<options>]
16
18 Fetches named heads or tags from one or more other repositories, along
19 with the objects necessary to complete them.
20
21 The ref names and their object names of fetched refs are stored in
22 .git/FETCH_HEAD. This information is left for a later merge operation
23 done by git merge.
24
25 When <refspec> stores the fetched result in remote-tracking branches,
26 the tags that point at these branches are automatically followed. This
27 is done by first fetching from the remote using the given <refspec>s,
28 and if the repository has objects that are pointed by remote tags that
29 it does not yet have, then fetch those missing tags. If the other end
30 has tags that point at branches you are not interested in, you will not
31 get them.
32
33 git fetch can fetch from either a single named repository, or or from
34 several repositories at once if <group> is given and there is a
35 remotes.<group> entry in the configuration file. (See git-config(1)).
36
38 --all
39 Fetch all remotes.
40
41 -a, --append
42 Append ref names and object names of fetched refs to the existing
43 contents of .git/FETCH_HEAD. Without this option old data in
44 .git/FETCH_HEAD will be overwritten.
45
46 --depth=<depth>
47 Deepen the history of a shallow repository created by git clone
48 with --depth=<depth> option (see git-clone(1)) by the specified
49 number of commits.
50
51 --dry-run
52 Show what would be done, without making any changes.
53
54 -f, --force
55 When git fetch is used with <rbranch>:<lbranch> refspec, it refuses
56 to update the local branch <lbranch> unless the remote branch
57 <rbranch> it fetches is a descendant of <lbranch>. This option
58 overrides that check.
59
60 -k, --keep
61 Keep downloaded pack.
62
63 --multiple
64 Allow several <repository> and <group> arguments to be specified.
65 No <refspec>s may be specified.
66
67 -p, --prune
68 After fetching, remove any remote-tracking branches which no longer
69 exist on the remote.
70
71 -n, --no-tags
72 By default, tags that point at objects that are downloaded from the
73 remote repository are fetched and stored locally. This option
74 disables this automatic tag following. The default behavior for a
75 remote may be specified with the remote.<name>.tagopt setting. See
76 git-config(1).
77
78 -t, --tags
79 Most of the tags are fetched automatically as branch heads are
80 downloaded, but tags that do not point at objects reachable from
81 the branch heads that are being tracked will not be fetched by this
82 mechanism. This flag lets all tags and their associated objects be
83 downloaded. The default behavior for a remote may be specified with
84 the remote.<name>.tagopt setting. See git-config(1).
85
86 --[no-]recurse-submodules
87 This option controls if new commits of all populated submodules
88 should be fetched too (see git-config(1) and gitmodules(5)).
89
90 --submodule-prefix=<path>
91 Prepend <path> to paths printed in informative messages such as
92 "Fetching submodule foo". This option is used internally when
93 recursing over submodules.
94
95 -u, --update-head-ok
96 By default git fetch refuses to update the head which corresponds
97 to the current branch. This flag disables the check. This is purely
98 for the internal use for git pull to communicate with git fetch,
99 and unless you are implementing your own Porcelain you are not
100 supposed to use it.
101
102 --upload-pack <upload-pack>
103 When given, and the repository to fetch from is handled by git
104 fetch-pack, --exec=<upload-pack> is passed to the command to
105 specify non-default path for the command run on the other end.
106
107 -q, --quiet
108 Pass --quiet to git-fetch-pack and silence any other internally
109 used git commands. Progress is not reported to the standard error
110 stream.
111
112 -v, --verbose
113 Be verbose.
114
115 --progress
116 Progress status is reported on the standard error stream by default
117 when it is attached to a terminal, unless -q is specified. This
118 flag forces progress status even if the standard error stream is
119 not directed to a terminal.
120
121 <repository>
122 The "remote" repository that is the source of a fetch or pull
123 operation. This parameter can be either a URL (see the section GIT
124 URLS below) or the name of a remote (see the section REMOTES
125 below).
126
127 <group>
128 A name referring to a list of repositories as the value of
129 remotes.<group> in the configuration file. (See git-config(1)).
130
131 <refspec>
132 The format of a <refspec> parameter is an optional plus +, followed
133 by the source ref <src>, followed by a colon :, followed by the
134 destination ref <dst>.
135
136 The remote ref that matches <src> is fetched, and if <dst> is not
137 empty string, the local ref that matches it is fast-forwarded using
138 <src>. If the optional plus + is used, the local ref is updated
139 even if it does not result in a fast-forward update.
140
141 Note
142 If the remote branch from which you want to pull is modified in
143 non-linear ways such as being rewound and rebased frequently,
144 then a pull will attempt a merge with an older version of
145 itself, likely conflict, and fail. It is under these conditions
146 that you would want to use the + sign to indicate
147 non-fast-forward updates will be needed. There is currently no
148 easy way to determine or declare that a branch will be made
149 available in a repository with this behavior; the pulling user
150 simply must know this is the expected usage pattern for a
151 branch.
152
153 Note
154 You never do your own development on branches that appear on
155 the right hand side of a <refspec> colon on Pull: lines; they
156 are to be updated by git fetch. If you intend to do development
157 derived from a remote branch B, have a Pull: line to track it
158 (i.e. Pull: B:remote-B), and have a separate branch my-B to do
159 your development on top of it. The latter is created by git
160 branch my-B remote-B (or its equivalent git checkout -b my-B
161 remote-B). Run git fetch to keep track of the progress of the
162 remote side, and when you see something new on the remote
163 branch, merge it into your development branch with git pull .
164 remote-B, while you are on my-B branch.
165
166 Note
167 There is a difference between listing multiple <refspec>
168 directly on git pull command line and having multiple Pull:
169 <refspec> lines for a <repository> and running git pull command
170 without any explicit <refspec> parameters. <refspec> listed
171 explicitly on the command line are always merged into the
172 current branch after fetching. In other words, if you list more
173 than one remote refs, you would be making an Octopus. While git
174 pull run without any explicit <refspec> parameter takes default
175 <refspec>s from Pull: lines, it merges only the first <refspec>
176 found into the current branch, after fetching all the remote
177 refs. This is because making an Octopus from remote refs is
178 rarely done, while keeping track of multiple remote heads in
179 one-go by fetching more than one is often useful.
180 Some short-cut notations are also supported.
181
182 · tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>;
183 it requests fetching everything up to the given tag.
184
185 · A parameter <ref> without a colon is equivalent to <ref>: when
186 pulling/fetching, so it merges <ref> into the current branch
187 without storing the remote branch anywhere locally
188
190 In general, URLs contain information about the transport protocol, the
191 address of the remote server, and the path to the repository. Depending
192 on the transport protocol, some of this information may be absent.
193
194 Git natively supports ssh, git, http, https, ftp, ftps, and rsync
195 protocols. The following syntaxes may be used with them:
196
197 · ssh://[user@]host.xz[:port]/path/to/repo.git/
198
199 · git://host.xz[:port]/path/to/repo.git/
200
201 · http[s]://host.xz[:port]/path/to/repo.git/
202
203 · ftp[s]://host.xz[:port]/path/to/repo.git/
204
205 · rsync://host.xz/path/to/repo.git/
206
207 An alternative scp-like syntax may also be used with the ssh protocol:
208
209 · [user@]host.xz:path/to/repo.git/
210
211 The ssh and git protocols additionally support ~username expansion:
212
213 · ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
214
215 · git://host.xz[:port]/~[user]/path/to/repo.git/
216
217 · [user@]host.xz:/~[user]/path/to/repo.git/
218
219 For local repositories, also supported by git natively, the following
220 syntaxes may be used:
221
222 · /path/to/repo.git/
223
224 · file:///path/to/repo.git/
225
226 These two syntaxes are mostly equivalent, except when cloning, when the
227 former implies --local option. See git-clone(1) for details.
228
229 When git doesn’t know how to handle a certain transport protocol, it
230 attempts to use the remote-<transport> remote helper, if one exists. To
231 explicitly request a remote helper, the following syntax may be used:
232
233 · <transport>::<address>
234
235 where <address> may be a path, a server and path, or an arbitrary
236 URL-like string recognized by the specific remote helper being invoked.
237 See git-remote-helpers(1) for details.
238
239 If there are a large number of similarly-named remote repositories and
240 you want to use a different format for them (such that the URLs you use
241 will be rewritten into URLs that work), you can create a configuration
242 section of the form:
243
244 [url "<actual url base>"]
245 insteadOf = <other url base>
246
247
248 For example, with this:
249
250 [url "git://git.host.xz/"]
251 insteadOf = host.xz:/path/to/
252 insteadOf = work:
253
254
255 a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
256 rewritten in any context that takes a URL to be
257 "git://git.host.xz/repo.git".
258
259 If you want to rewrite URLs for push only, you can create a
260 configuration section of the form:
261
262 [url "<actual url base>"]
263 pushInsteadOf = <other url base>
264
265
266 For example, with this:
267
268 [url "ssh://example.org/"]
269 pushInsteadOf = git://example.org/
270
271
272 a URL like "git://example.org/path/to/repo.git" will be rewritten to
273 "ssh://example.org/path/to/repo.git" for pushes, but pulls will still
274 use the original URL.
275
277 The name of one of the following can be used instead of a URL as
278 <repository> argument:
279
280 · a remote in the git configuration file: $GIT_DIR/config,
281
282 · a file in the $GIT_DIR/remotes directory, or
283
284 · a file in the $GIT_DIR/branches directory.
285
286 All of these also allow you to omit the refspec from the command line
287 because they each contain a refspec which git will use by default.
288
289 Named remote in configuration file
290 You can choose to provide the name of a remote which you had previously
291 configured using git-remote(1), git-config(1) or even by a manual edit
292 to the $GIT_DIR/config file. The URL of this remote will be used to
293 access the repository. The refspec of this remote will be used by
294 default when you do not provide a refspec on the command line. The
295 entry in the config file would appear like this:
296
297 [remote "<name>"]
298 url = <url>
299 pushurl = <pushurl>
300 push = <refspec>
301 fetch = <refspec>
302
303
304 The <pushurl> is used for pushes only. It is optional and defaults to
305 <url>.
306
307 Named file in $GIT_DIR/remotes
308 You can choose to provide the name of a file in $GIT_DIR/remotes. The
309 URL in this file will be used to access the repository. The refspec in
310 this file will be used as default when you do not provide a refspec on
311 the command line. This file should have the following format:
312
313 URL: one of the above URL format
314 Push: <refspec>
315 Pull: <refspec>
316
317
318 Push: lines are used by git push and Pull: lines are used by git pull
319 and git fetch. Multiple Push: and Pull: lines may be specified for
320 additional branch mappings.
321
322 Named file in $GIT_DIR/branches
323 You can choose to provide the name of a file in $GIT_DIR/branches. The
324 URL in this file will be used to access the repository. This file
325 should have the following format:
326
327 <url>#<head>
328
329
330 <url> is required; #<head> is optional.
331
332 Depending on the operation, git will use one of the following refspecs,
333 if you don’t provide one on the command line. <branch> is the name of
334 this file in $GIT_DIR/branches and <head> defaults to master.
335
336 git fetch uses:
337
338 refs/heads/<head>:refs/heads/<branch>
339
340
341 git push uses:
342
343 HEAD:refs/heads/<head>
344
345
347 · Update the remote-tracking branches:
348
349 $ git fetch origin
350
351 The above command copies all branches from the remote refs/heads/
352 namespace and stores them to the local refs/remotes/origin/
353 namespace, unless the branch.<name>.fetch option is used to specify
354 a non-default refspec.
355
356 · Using refspecs explicitly:
357
358 $ git fetch origin +pu:pu maint:tmp
359
360 This updates (or creates, as necessary) branches pu and tmp in the
361 local repository by fetching from the branches (respectively) pu
362 and maint from the remote repository.
363
364 The pu branch will be updated even if it is does not fast-forward,
365 because it is prefixed with a plus sign; tmp will not be.
366
368 git-pull(1)
369
371 Written by Linus Torvalds <torvalds@osdl.org[1]> and Junio C Hamano
372 <gitster@pobox.com[2]>
373
375 Documentation by David Greaves, Junio C Hamano and the git-list
376 <git@vger.kernel.org[3]>.
377
379 Part of the git(1) suite
380
382 1. torvalds@osdl.org
383 mailto:torvalds@osdl.org
384
385 2. gitster@pobox.com
386 mailto:gitster@pobox.com
387
388 3. git@vger.kernel.org
389 mailto:git@vger.kernel.org
390
391
392
393Git 1.7.4.4 04/11/2011 GIT-FETCH(1)