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 git fetch [<options>] <group>
11 git fetch --multiple [<options>] [(<repository> | <group>)...]
12 git fetch --all [<options>]
13
15 Fetch branches and/or tags (collectively, "refs") from one or more
16 other repositories, along with the objects necessary to complete their
17 histories. Remote-tracking branches are updated (see the description of
18 <refspec> below for ways to control this behavior).
19
20 By default, any tag that points into the histories being fetched is
21 also fetched; the effect is to fetch tags that point at branches that
22 you are interested in. This default behavior can be changed by using
23 the --tags or --no-tags options or by configuring remote.<name>.tagOpt.
24 By using a refspec that fetches tags explicitly, you can fetch tags
25 that do not point into branches you are interested in as well.
26
27 git fetch can fetch from either a single named repository or URL, or
28 from several repositories at once if <group> is given and there is a
29 remotes.<group> entry in the configuration file. (See git-config(1)).
30
31 When no remote is specified, by default the origin remote will be used,
32 unless there’s an upstream branch configured for the current branch.
33
34 The names of refs that are fetched, together with the object names they
35 point at, are written to .git/FETCH_HEAD. This information may be used
36 by scripts or other git commands, such as git-pull(1).
37
39 --all
40 Fetch all remotes.
41
42 -a, --append
43 Append ref names and object names of fetched refs to the existing
44 contents of .git/FETCH_HEAD. Without this option old data in
45 .git/FETCH_HEAD will be overwritten.
46
47 --atomic
48 Use an atomic transaction to update local refs. Either all refs are
49 updated, or on error, no refs are updated.
50
51 --depth=<depth>
52 Limit fetching to the specified number of commits from the tip of
53 each remote branch history. If fetching to a shallow repository
54 created by git clone with --depth=<depth> option (see git-
55 clone(1)), deepen or shorten the history to the specified number of
56 commits. Tags for the deepened commits are not fetched.
57
58 --deepen=<depth>
59 Similar to --depth, except it specifies the number of commits from
60 the current shallow boundary instead of from the tip of each remote
61 branch history.
62
63 --shallow-since=<date>
64 Deepen or shorten the history of a shallow repository to include
65 all reachable commits after <date>.
66
67 --shallow-exclude=<revision>
68 Deepen or shorten the history of a shallow repository to exclude
69 commits reachable from a specified remote branch or tag. This
70 option can be specified multiple times.
71
72 --unshallow
73 If the source repository is complete, convert a shallow repository
74 to a complete one, removing all the limitations imposed by shallow
75 repositories.
76
77 If the source repository is shallow, fetch as much as possible so
78 that the current repository has the same history as the source
79 repository.
80
81 --update-shallow
82 By default when fetching from a shallow repository, git fetch
83 refuses refs that require updating .git/shallow. This option
84 updates .git/shallow and accept such refs.
85
86 --negotiation-tip=<commit|glob>
87 By default, Git will report, to the server, commits reachable from
88 all local refs to find common commits in an attempt to reduce the
89 size of the to-be-received packfile. If specified, Git will only
90 report commits reachable from the given tips. This is useful to
91 speed up fetches when the user knows which local ref is likely to
92 have commits in common with the upstream ref being fetched.
93
94 This option may be specified more than once; if so, Git will report
95 commits reachable from any of the given commits.
96
97 The argument to this option may be a glob on ref names, a ref, or
98 the (possibly abbreviated) SHA-1 of a commit. Specifying a glob is
99 equivalent to specifying this option multiple times, one for each
100 matching ref name.
101
102 See also the fetch.negotiationAlgorithm and push.negotiate
103 configuration variables documented in git-config(1), and the
104 --negotiate-only option below.
105
106 --negotiate-only
107 Do not fetch anything from the server, and instead print the
108 ancestors of the provided --negotiation-tip=* arguments, which we
109 have in common with the server.
110
111 This is incompatible with --recurse-submodules=[yes|on-demand].
112 Internally this is used to implement the push.negotiate option, see
113 git-config(1).
114
115 --dry-run
116 Show what would be done, without making any changes.
117
118 --[no-]write-fetch-head
119 Write the list of remote refs fetched in the FETCH_HEAD file
120 directly under $GIT_DIR. This is the default. Passing
121 --no-write-fetch-head from the command line tells Git not to write
122 the file. Under --dry-run option, the file is never written.
123
124 -f, --force
125 When git fetch is used with <src>:<dst> refspec it may refuse to
126 update the local branch as discussed in the <refspec> part below.
127 This option overrides that check.
128
129 -k, --keep
130 Keep downloaded pack.
131
132 --multiple
133 Allow several <repository> and <group> arguments to be specified.
134 No <refspec>s may be specified.
135
136 --[no-]auto-maintenance, --[no-]auto-gc
137 Run git maintenance run --auto at the end to perform automatic
138 repository maintenance if needed. (--[no-]auto-gc is a synonym.)
139 This is enabled by default.
140
141 --[no-]write-commit-graph
142 Write a commit-graph after fetching. This overrides the config
143 setting fetch.writeCommitGraph.
144
145 --prefetch
146 Modify the configured refspec to place all refs into the
147 refs/prefetch/ namespace. See the prefetch task in git-
148 maintenance(1).
149
150 -p, --prune
151 Before fetching, remove any remote-tracking references that no
152 longer exist on the remote. Tags are not subject to pruning if they
153 are fetched only because of the default tag auto-following or due
154 to a --tags option. However, if tags are fetched due to an explicit
155 refspec (either on the command line or in the remote configuration,
156 for example if the remote was cloned with the --mirror option),
157 then they are also subject to pruning. Supplying --prune-tags is a
158 shorthand for providing the tag refspec.
159
160 See the PRUNING section below for more details.
161
162 -P, --prune-tags
163 Before fetching, remove any local tags that no longer exist on the
164 remote if --prune is enabled. This option should be used more
165 carefully, unlike --prune it will remove any local references
166 (local tags) that have been created. This option is a shorthand for
167 providing the explicit tag refspec along with --prune, see the
168 discussion about that in its documentation.
169
170 See the PRUNING section below for more details.
171
172 -n, --no-tags
173 By default, tags that point at objects that are downloaded from the
174 remote repository are fetched and stored locally. This option
175 disables this automatic tag following. The default behavior for a
176 remote may be specified with the remote.<name>.tagOpt setting. See
177 git-config(1).
178
179 --refetch
180 Instead of negotiating with the server to avoid transferring
181 commits and associated objects that are already present locally,
182 this option fetches all objects as a fresh clone would. Use this to
183 reapply a partial clone filter from configuration or using
184 --filter= when the filter definition has changed. Automatic
185 post-fetch maintenance will perform object database pack
186 consolidation to remove any duplicate objects.
187
188 --refmap=<refspec>
189 When fetching refs listed on the command line, use the specified
190 refspec (can be given more than once) to map the refs to
191 remote-tracking branches, instead of the values of remote.*.fetch
192 configuration variables for the remote repository. Providing an
193 empty <refspec> to the --refmap option causes Git to ignore the
194 configured refspecs and rely entirely on the refspecs supplied as
195 command-line arguments. See section on "Configured Remote-tracking
196 Branches" for details.
197
198 -t, --tags
199 Fetch all tags from the remote (i.e., fetch remote tags refs/tags/*
200 into local tags with the same name), in addition to whatever else
201 would otherwise be fetched. Using this option alone does not
202 subject tags to pruning, even if --prune is used (though tags may
203 be pruned anyway if they are also the destination of an explicit
204 refspec; see --prune).
205
206 --recurse-submodules[=yes|on-demand|no]
207 This option controls if and under what conditions new commits of
208 submodules should be fetched too. When recursing through
209 submodules, git fetch always attempts to fetch "changed"
210 submodules, that is, a submodule that has commits that are
211 referenced by a newly fetched superproject commit but are missing
212 in the local submodule clone. A changed submodule can be fetched as
213 long as it is present locally e.g. in $GIT_DIR/modules/ (see
214 gitsubmodules(7)); if the upstream adds a new submodule, that
215 submodule cannot be fetched until it is cloned e.g. by git
216 submodule update.
217
218 When set to on-demand, only changed submodules are fetched. When
219 set to yes, all populated submodules are fetched and submodules
220 that are both unpopulated and changed are fetched. When set to no,
221 submodules are never fetched.
222
223 When unspecified, this uses the value of fetch.recurseSubmodules if
224 it is set (see git-config(1)), defaulting to on-demand if unset.
225 When this option is used without any value, it defaults to yes.
226
227 -j, --jobs=<n>
228 Number of parallel children to be used for all forms of fetching.
229
230 If the --multiple option was specified, the different remotes will
231 be fetched in parallel. If multiple submodules are fetched, they
232 will be fetched in parallel. To control them independently, use the
233 config settings fetch.parallel and submodule.fetchJobs (see git-
234 config(1)).
235
236 Typically, parallel recursive and multi-remote fetches will be
237 faster. By default fetches are performed sequentially, not in
238 parallel.
239
240 --no-recurse-submodules
241 Disable recursive fetching of submodules (this has the same effect
242 as using the --recurse-submodules=no option).
243
244 --set-upstream
245 If the remote is fetched successfully, add upstream (tracking)
246 reference, used by argument-less git-pull(1) and other commands.
247 For more information, see branch.<name>.merge and
248 branch.<name>.remote in git-config(1).
249
250 --submodule-prefix=<path>
251 Prepend <path> to paths printed in informative messages such as
252 "Fetching submodule foo". This option is used internally when
253 recursing over submodules.
254
255 --recurse-submodules-default=[yes|on-demand]
256 This option is used internally to temporarily provide a
257 non-negative default value for the --recurse-submodules option. All
258 other methods of configuring fetch’s submodule recursion (such as
259 settings in gitmodules(5) and git-config(1)) override this option,
260 as does specifying --[no-]recurse-submodules directly.
261
262 -u, --update-head-ok
263 By default git fetch refuses to update the head which corresponds
264 to the current branch. This flag disables the check. This is purely
265 for the internal use for git pull to communicate with git fetch,
266 and unless you are implementing your own Porcelain you are not
267 supposed to use it.
268
269 --upload-pack <upload-pack>
270 When given, and the repository to fetch from is handled by git
271 fetch-pack, --exec=<upload-pack> is passed to the command to
272 specify non-default path for the command run on the other end.
273
274 -q, --quiet
275 Pass --quiet to git-fetch-pack and silence any other internally
276 used git commands. Progress is not reported to the standard error
277 stream.
278
279 -v, --verbose
280 Be verbose.
281
282 --progress
283 Progress status is reported on the standard error stream by default
284 when it is attached to a terminal, unless -q is specified. This
285 flag forces progress status even if the standard error stream is
286 not directed to a terminal.
287
288 -o <option>, --server-option=<option>
289 Transmit the given string to the server when communicating using
290 protocol version 2. The given string must not contain a NUL or LF
291 character. The server’s handling of server options, including
292 unknown ones, is server-specific. When multiple
293 --server-option=<option> are given, they are all sent to the other
294 side in the order listed on the command line.
295
296 --show-forced-updates
297 By default, git checks if a branch is force-updated during fetch.
298 This can be disabled through fetch.showForcedUpdates, but the
299 --show-forced-updates option guarantees this check occurs. See git-
300 config(1).
301
302 --no-show-forced-updates
303 By default, git checks if a branch is force-updated during fetch.
304 Pass --no-show-forced-updates or set fetch.showForcedUpdates to
305 false to skip this check for performance reasons. If used during
306 git-pull the --ff-only option will still check for forced updates
307 before attempting a fast-forward update. See git-config(1).
308
309 -4, --ipv4
310 Use IPv4 addresses only, ignoring IPv6 addresses.
311
312 -6, --ipv6
313 Use IPv6 addresses only, ignoring IPv4 addresses.
314
315 <repository>
316 The "remote" repository that is the source of a fetch or pull
317 operation. This parameter can be either a URL (see the section GIT
318 URLS below) or the name of a remote (see the section REMOTES
319 below).
320
321 <group>
322 A name referring to a list of repositories as the value of
323 remotes.<group> in the configuration file. (See git-config(1)).
324
325 <refspec>
326 Specifies which refs to fetch and which local refs to update. When
327 no <refspec>s appear on the command line, the refs to fetch are
328 read from remote.<repository>.fetch variables instead (see
329 CONFIGURED REMOTE-TRACKING BRANCHES below).
330
331 The format of a <refspec> parameter is an optional plus +, followed
332 by the source <src>, followed by a colon :, followed by the
333 destination ref <dst>. The colon can be omitted when <dst> is
334 empty. <src> is typically a ref, but it can also be a fully spelled
335 hex object name.
336
337 A <refspec> may contain a * in its <src> to indicate a simple
338 pattern match. Such a refspec functions like a glob that matches
339 any ref with the same prefix. A pattern <refspec> must have a * in
340 both the <src> and <dst>. It will map refs to the destination by
341 replacing the * with the contents matched from the source.
342
343 If a refspec is prefixed by ^, it will be interpreted as a negative
344 refspec. Rather than specifying which refs to fetch or which local
345 refs to update, such a refspec will instead specify refs to
346 exclude. A ref will be considered to match if it matches at least
347 one positive refspec, and does not match any negative refspec.
348 Negative refspecs can be useful to restrict the scope of a pattern
349 refspec so that it will not include specific refs. Negative
350 refspecs can themselves be pattern refspecs. However, they may only
351 contain a <src> and do not specify a <dst>. Fully spelled out hex
352 object names are also not supported.
353
354 tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>; it
355 requests fetching everything up to the given tag.
356
357 The remote ref that matches <src> is fetched, and if <dst> is not
358 an empty string, an attempt is made to update the local ref that
359 matches it.
360
361 Whether that update is allowed without --force depends on the ref
362 namespace it’s being fetched to, the type of object being fetched,
363 and whether the update is considered to be a fast-forward.
364 Generally, the same rules apply for fetching as when pushing, see
365 the <refspec>... section of git-push(1) for what those are.
366 Exceptions to those rules particular to git fetch are noted below.
367
368 Until Git version 2.20, and unlike when pushing with git-push(1),
369 any updates to refs/tags/* would be accepted without + in the
370 refspec (or --force). When fetching, we promiscuously considered
371 all tag updates from a remote to be forced fetches. Since Git
372 version 2.20, fetching to update refs/tags/* works the same way as
373 when pushing. I.e. any updates will be rejected without + in the
374 refspec (or --force).
375
376 Unlike when pushing with git-push(1), any updates outside of
377 refs/{tags,heads}/* will be accepted without + in the refspec (or
378 --force), whether that’s swapping e.g. a tree object for a blob, or
379 a commit for another commit that’s doesn’t have the previous commit
380 as an ancestor etc.
381
382 Unlike when pushing with git-push(1), there is no configuration
383 which’ll amend these rules, and nothing like a pre-fetch hook
384 analogous to the pre-receive hook.
385
386 As with pushing with git-push(1), all of the rules described above
387 about what’s not allowed as an update can be overridden by adding
388 an the optional leading + to a refspec (or using --force command
389 line option). The only exception to this is that no amount of
390 forcing will make the refs/heads/* namespace accept a non-commit
391 object.
392
393 Note
394 When the remote branch you want to fetch is known to be rewound
395 and rebased regularly, it is expected that its new tip will not
396 be descendant of its previous tip (as stored in your
397 remote-tracking branch the last time you fetched). You would
398 want to use the + sign to indicate non-fast-forward updates
399 will be needed for such branches. There is no way to determine
400 or declare that a branch will be made available in a repository
401 with this behavior; the pulling user simply must know this is
402 the expected usage pattern for a branch.
403
404 --stdin
405 Read refspecs, one per line, from stdin in addition to those
406 provided as arguments. The "tag <name>" format is not supported.
407
409 In general, URLs contain information about the transport protocol, the
410 address of the remote server, and the path to the repository. Depending
411 on the transport protocol, some of this information may be absent.
412
413 Git supports ssh, git, http, and https protocols (in addition, ftp, and
414 ftps can be used for fetching, but this is inefficient and deprecated;
415 do not use it).
416
417 The native transport (i.e. git:// URL) does no authentication and
418 should be used with caution on unsecured networks.
419
420 The following syntaxes may be used with them:
421
422 • ssh://[user@]host.xz[:port]/path/to/repo.git/
423
424 • git://host.xz[:port]/path/to/repo.git/
425
426 • http[s]://host.xz[:port]/path/to/repo.git/
427
428 • ftp[s]://host.xz[:port]/path/to/repo.git/
429
430 An alternative scp-like syntax may also be used with the ssh protocol:
431
432 • [user@]host.xz:path/to/repo.git/
433
434 This syntax is only recognized if there are no slashes before the first
435 colon. This helps differentiate a local path that contains a colon. For
436 example the local path foo:bar could be specified as an absolute path
437 or ./foo:bar to avoid being misinterpreted as an ssh url.
438
439 The ssh and git protocols additionally support ~username expansion:
440
441 • ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
442
443 • git://host.xz[:port]/~[user]/path/to/repo.git/
444
445 • [user@]host.xz:/~[user]/path/to/repo.git/
446
447 For local repositories, also supported by Git natively, the following
448 syntaxes may be used:
449
450 • /path/to/repo.git/
451
452 • file:///path/to/repo.git/
453
454 These two syntaxes are mostly equivalent, except when cloning, when the
455 former implies --local option. See git-clone(1) for details.
456
457 git clone, git fetch and git pull, but not git push, will also accept a
458 suitable bundle file. See git-bundle(1).
459
460 When Git doesn’t know how to handle a certain transport protocol, it
461 attempts to use the remote-<transport> remote helper, if one exists. To
462 explicitly request a remote helper, the following syntax may be used:
463
464 • <transport>::<address>
465
466 where <address> may be a path, a server and path, or an arbitrary
467 URL-like string recognized by the specific remote helper being invoked.
468 See gitremote-helpers(7) for details.
469
470 If there are a large number of similarly-named remote repositories and
471 you want to use a different format for them (such that the URLs you use
472 will be rewritten into URLs that work), you can create a configuration
473 section of the form:
474
475 [url "<actual url base>"]
476 insteadOf = <other url base>
477
478 For example, with this:
479
480 [url "git://git.host.xz/"]
481 insteadOf = host.xz:/path/to/
482 insteadOf = work:
483
484 a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
485 rewritten in any context that takes a URL to be
486 "git://git.host.xz/repo.git".
487
488 If you want to rewrite URLs for push only, you can create a
489 configuration section of the form:
490
491 [url "<actual url base>"]
492 pushInsteadOf = <other url base>
493
494 For example, with this:
495
496 [url "ssh://example.org/"]
497 pushInsteadOf = git://example.org/
498
499 a URL like "git://example.org/path/to/repo.git" will be rewritten to
500 "ssh://example.org/path/to/repo.git" for pushes, but pulls will still
501 use the original URL.
502
504 The name of one of the following can be used instead of a URL as
505 <repository> argument:
506
507 • a remote in the Git configuration file: $GIT_DIR/config,
508
509 • a file in the $GIT_DIR/remotes directory, or
510
511 • a file in the $GIT_DIR/branches directory.
512
513 All of these also allow you to omit the refspec from the command line
514 because they each contain a refspec which git will use by default.
515
516 Named remote in configuration file
517 You can choose to provide the name of a remote which you had previously
518 configured using git-remote(1), git-config(1) or even by a manual edit
519 to the $GIT_DIR/config file. The URL of this remote will be used to
520 access the repository. The refspec of this remote will be used by
521 default when you do not provide a refspec on the command line. The
522 entry in the config file would appear like this:
523
524 [remote "<name>"]
525 url = <URL>
526 pushurl = <pushurl>
527 push = <refspec>
528 fetch = <refspec>
529
530 The <pushurl> is used for pushes only. It is optional and defaults to
531 <URL>.
532
533 Named file in $GIT_DIR/remotes
534 You can choose to provide the name of a file in $GIT_DIR/remotes. The
535 URL in this file will be used to access the repository. The refspec in
536 this file will be used as default when you do not provide a refspec on
537 the command line. This file should have the following format:
538
539 URL: one of the above URL format
540 Push: <refspec>
541 Pull: <refspec>
542
543 Push: lines are used by git push and Pull: lines are used by git pull
544 and git fetch. Multiple Push: and Pull: lines may be specified for
545 additional branch mappings.
546
547 Named file in $GIT_DIR/branches
548 You can choose to provide the name of a file in $GIT_DIR/branches. The
549 URL in this file will be used to access the repository. This file
550 should have the following format:
551
552 <URL>#<head>
553
554 <URL> is required; #<head> is optional.
555
556 Depending on the operation, git will use one of the following refspecs,
557 if you don’t provide one on the command line. <branch> is the name of
558 this file in $GIT_DIR/branches and <head> defaults to master.
559
560 git fetch uses:
561
562 refs/heads/<head>:refs/heads/<branch>
563
564 git push uses:
565
566 HEAD:refs/heads/<head>
567
569 You often interact with the same remote repository by regularly and
570 repeatedly fetching from it. In order to keep track of the progress of
571 such a remote repository, git fetch allows you to configure
572 remote.<repository>.fetch configuration variables.
573
574 Typically such a variable may look like this:
575
576 [remote "origin"]
577 fetch = +refs/heads/*:refs/remotes/origin/*
578
579 This configuration is used in two ways:
580
581 • When git fetch is run without specifying what branches and/or tags
582 to fetch on the command line, e.g. git fetch origin or git fetch,
583 remote.<repository>.fetch values are used as the refspecs—they
584 specify which refs to fetch and which local refs to update. The
585 example above will fetch all branches that exist in the origin
586 (i.e. any ref that matches the left-hand side of the value,
587 refs/heads/*) and update the corresponding remote-tracking branches
588 in the refs/remotes/origin/* hierarchy.
589
590 • When git fetch is run with explicit branches and/or tags to fetch
591 on the command line, e.g. git fetch origin master, the <refspec>s
592 given on the command line determine what are to be fetched (e.g.
593 master in the example, which is a short-hand for master:, which in
594 turn means "fetch the master branch but I do not explicitly say
595 what remote-tracking branch to update with it from the command
596 line"), and the example command will fetch only the master branch.
597 The remote.<repository>.fetch values determine which
598 remote-tracking branch, if any, is updated. When used in this way,
599 the remote.<repository>.fetch values do not have any effect in
600 deciding what gets fetched (i.e. the values are not used as
601 refspecs when the command-line lists refspecs); they are only used
602 to decide where the refs that are fetched are stored by acting as a
603 mapping.
604
605 The latter use of the remote.<repository>.fetch values can be
606 overridden by giving the --refmap=<refspec> parameter(s) on the command
607 line.
608
610 Git has a default disposition of keeping data unless it’s explicitly
611 thrown away; this extends to holding onto local references to branches
612 on remotes that have themselves deleted those branches.
613
614 If left to accumulate, these stale references might make performance
615 worse on big and busy repos that have a lot of branch churn, and e.g.
616 make the output of commands like git branch -a --contains <commit>
617 needlessly verbose, as well as impacting anything else that’ll work
618 with the complete set of known references.
619
620 These remote-tracking references can be deleted as a one-off with
621 either of:
622
623 # While fetching
624 $ git fetch --prune <name>
625
626 # Only prune, don't fetch
627 $ git remote prune <name>
628
629 To prune references as part of your normal workflow without needing to
630 remember to run that, set fetch.prune globally, or remote.<name>.prune
631 per-remote in the config. See git-config(1).
632
633 Here’s where things get tricky and more specific. The pruning feature
634 doesn’t actually care about branches, instead it’ll prune local ←→
635 remote-references as a function of the refspec of the remote (see
636 <refspec> and CONFIGURED REMOTE-TRACKING BRANCHES above).
637
638 Therefore if the refspec for the remote includes e.g.
639 refs/tags/*:refs/tags/*, or you manually run e.g. git fetch --prune
640 <name> "refs/tags/*:refs/tags/*" it won’t be stale remote tracking
641 branches that are deleted, but any local tag that doesn’t exist on the
642 remote.
643
644 This might not be what you expect, i.e. you want to prune remote
645 <name>, but also explicitly fetch tags from it, so when you fetch from
646 it you delete all your local tags, most of which may not have come from
647 the <name> remote in the first place.
648
649 So be careful when using this with a refspec like
650 refs/tags/*:refs/tags/*, or any other refspec which might map
651 references from multiple remotes to the same local namespace.
652
653 Since keeping up-to-date with both branches and tags on the remote is a
654 common use-case the --prune-tags option can be supplied along with
655 --prune to prune local tags that don’t exist on the remote, and
656 force-update those tags that differ. Tag pruning can also be enabled
657 with fetch.pruneTags or remote.<name>.pruneTags in the config. See git-
658 config(1).
659
660 The --prune-tags option is equivalent to having refs/tags/*:refs/tags/*
661 declared in the refspecs of the remote. This can lead to some seemingly
662 strange interactions:
663
664 # These both fetch tags
665 $ git fetch --no-tags origin 'refs/tags/*:refs/tags/*'
666 $ git fetch --no-tags --prune-tags origin
667
668 The reason it doesn’t error out when provided without --prune or its
669 config versions is for flexibility of the configured versions, and to
670 maintain a 1=1 mapping between what the command line flags do, and what
671 the configuration versions do.
672
673 It’s reasonable to e.g. configure fetch.pruneTags=true in ~/.gitconfig
674 to have tags pruned whenever git fetch --prune is run, without making
675 every invocation of git fetch without --prune an error.
676
677 Pruning tags with --prune-tags also works when fetching a URL instead
678 of a named remote. These will all prune tags not found on origin:
679
680 $ git fetch origin --prune --prune-tags
681 $ git fetch origin --prune 'refs/tags/*:refs/tags/*'
682 $ git fetch <url of origin> --prune --prune-tags
683 $ git fetch <url of origin> --prune 'refs/tags/*:refs/tags/*'
684
686 The output of "git fetch" depends on the transport method used; this
687 section describes the output when fetching over the Git protocol
688 (either locally or via ssh) and Smart HTTP protocol.
689
690 The status of the fetch is output in tabular form, with each line
691 representing the status of a single ref. Each line is of the form:
692
693 <flag> <summary> <from> -> <to> [<reason>]
694
695 The status of up-to-date refs is shown only if the --verbose option is
696 used.
697
698 In compact output mode, specified with configuration variable
699 fetch.output, if either entire <from> or <to> is found in the other
700 string, it will be substituted with * in the other string. For example,
701 master -> origin/master becomes master -> origin/*.
702
703 flag
704 A single character indicating the status of the ref:
705
706 (space)
707 for a successfully fetched fast-forward;
708
709 +
710 for a successful forced update;
711
712 -
713 for a successfully pruned ref;
714
715 t
716 for a successful tag update;
717
718 *
719 for a successfully fetched new ref;
720
721 !
722 for a ref that was rejected or failed to update; and
723
724 =
725 for a ref that was up to date and did not need fetching.
726
727 summary
728 For a successfully fetched ref, the summary shows the old and new
729 values of the ref in a form suitable for using as an argument to
730 git log (this is <old>..<new> in most cases, and <old>...<new> for
731 forced non-fast-forward updates).
732
733 from
734 The name of the remote ref being fetched from, minus its
735 refs/<type>/ prefix. In the case of deletion, the name of the
736 remote ref is "(none)".
737
738 to
739 The name of the local ref being updated, minus its refs/<type>/
740 prefix.
741
742 reason
743 A human-readable explanation. In the case of successfully fetched
744 refs, no explanation is needed. For a failed ref, the reason for
745 failure is described.
746
748 • Update the remote-tracking branches:
749
750 $ git fetch origin
751
752 The above command copies all branches from the remote refs/heads/
753 namespace and stores them to the local refs/remotes/origin/
754 namespace, unless the branch.<name>.fetch option is used to specify
755 a non-default refspec.
756
757 • Using refspecs explicitly:
758
759 $ git fetch origin +seen:seen maint:tmp
760
761 This updates (or creates, as necessary) branches seen and tmp in
762 the local repository by fetching from the branches (respectively)
763 seen and maint from the remote repository.
764
765 The seen branch will be updated even if it does not fast-forward,
766 because it is prefixed with a plus sign; tmp will not be.
767
768 • Peek at a remote’s branch, without configuring the remote in your
769 local repository:
770
771 $ git fetch git://git.kernel.org/pub/scm/git/git.git maint
772 $ git log FETCH_HEAD
773
774 The first command fetches the maint branch from the repository at
775 git://git.kernel.org/pub/scm/git/git.git and the second command
776 uses FETCH_HEAD to examine the branch with git-log(1). The fetched
777 objects will eventually be removed by git’s built-in housekeeping
778 (see git-gc(1)).
779
781 The fetch and push protocols are not designed to prevent one side from
782 stealing data from the other repository that was not intended to be
783 shared. If you have private data that you need to protect from a
784 malicious peer, your best option is to store it in another repository.
785 This applies to both clients and servers. In particular, namespaces on
786 a server are not effective for read access control; you should only
787 grant read access to a namespace to clients that you would trust with
788 read access to the entire repository.
789
790 The known attack vectors are as follows:
791
792 1. The victim sends "have" lines advertising the IDs of objects it has
793 that are not explicitly intended to be shared but can be used to
794 optimize the transfer if the peer also has them. The attacker
795 chooses an object ID X to steal and sends a ref to X, but isn’t
796 required to send the content of X because the victim already has
797 it. Now the victim believes that the attacker has X, and it sends
798 the content of X back to the attacker later. (This attack is most
799 straightforward for a client to perform on a server, by creating a
800 ref to X in the namespace the client has access to and then
801 fetching it. The most likely way for a server to perform it on a
802 client is to "merge" X into a public branch and hope that the user
803 does additional work on this branch and pushes it back to the
804 server without noticing the merge.)
805
806 2. As in #1, the attacker chooses an object ID X to steal. The victim
807 sends an object Y that the attacker already has, and the attacker
808 falsely claims to have X and not Y, so the victim sends Y as a
809 delta against X. The delta reveals regions of X that are similar to
810 Y to the attacker.
811
813 Using --recurse-submodules can only fetch new commits in submodules
814 that are present locally e.g. in $GIT_DIR/modules/. If the upstream
815 adds a new submodule, that submodule cannot be fetched until it is
816 cloned e.g. by git submodule update. This is expected to be fixed in a
817 future Git version.
818
820 git-pull(1)
821
823 Part of the git(1) suite
824
825
826
827Git 2.36.1 2022-05-05 GIT-FETCH(1)