1GIT-FETCH(1)                      Git Manual                      GIT-FETCH(1)
2
3
4

NAME

6       git-fetch - Download objects and refs from another repository
7

SYNOPSIS

9       git fetch [<options>] [<repository> [<refspec>...]]
10       git fetch [<options>] <group>
11       git fetch --multiple [<options>] [(<repository> | <group>)...]
12       git fetch --all [<options>]
13
14

DESCRIPTION

16       Fetch branches and/or tags (collectively, "refs") from one or more
17       other repositories, along with the objects necessary to complete their
18       histories. Remote-tracking branches are updated (see the description of
19       <refspec> below for ways to control this behavior).
20
21       By default, any tag that points into the histories being fetched is
22       also fetched; the effect is to fetch tags that point at branches that
23       you are interested in. This default behavior can be changed by using
24       the --tags or --no-tags options or by configuring remote.<name>.tagOpt.
25       By using a refspec that fetches tags explicitly, you can fetch tags
26       that do not point into branches you are interested in as well.
27
28       git fetch can fetch from either a single named repository or URL, or
29       from several repositories at once if <group> is given and there is a
30       remotes.<group> entry in the configuration file. (See git-config(1)).
31
32       When no remote is specified, by default the origin remote will be used,
33       unless there’s an upstream branch configured for the current branch.
34
35       The names of refs that are fetched, together with the object names they
36       point at, are written to .git/FETCH_HEAD. This information may be used
37       by scripts or other git commands, such as git-pull(1).
38

OPTIONS

40       --all
41           Fetch all remotes.
42
43       -a, --append
44           Append ref names and object names of fetched refs to the existing
45           contents of .git/FETCH_HEAD. Without this option old data in
46           .git/FETCH_HEAD will be overwritten.
47
48       --depth=<depth>
49           Limit fetching to the specified number of commits from the tip of
50           each remote branch history. If fetching to a shallow repository
51           created by git clone with --depth=<depth> option (see git-
52           clone(1)), deepen or shorten the history to the specified number of
53           commits. Tags for the deepened commits are not fetched.
54
55       --deepen=<depth>
56           Similar to --depth, except it specifies the number of commits from
57           the current shallow boundary instead of from the tip of each remote
58           branch history.
59
60       --shallow-since=<date>
61           Deepen or shorten the history of a shallow repository to include
62           all reachable commits after <date>.
63
64       --shallow-exclude=<revision>
65           Deepen or shorten the history of a shallow repository to exclude
66           commits reachable from a specified remote branch or tag. This
67           option can be specified multiple times.
68
69       --unshallow
70           If the source repository is complete, convert a shallow repository
71           to a complete one, removing all the limitations imposed by shallow
72           repositories.
73
74           If the source repository is shallow, fetch as much as possible so
75           that the current repository has the same history as the source
76           repository.
77
78       --update-shallow
79           By default when fetching from a shallow repository, git fetch
80           refuses refs that require updating .git/shallow. This option
81           updates .git/shallow and accept such refs.
82
83       --dry-run
84           Show what would be done, without making any changes.
85
86       -f, --force
87           When git fetch is used with <rbranch>:<lbranch> refspec, it refuses
88           to update the local branch <lbranch> unless the remote branch
89           <rbranch> it fetches is a descendant of <lbranch>. This option
90           overrides that check.
91
92       -k, --keep
93           Keep downloaded pack.
94
95       --multiple
96           Allow several <repository> and <group> arguments to be specified.
97           No <refspec>s may be specified.
98
99       -p, --prune
100           Before fetching, remove any remote-tracking references that no
101           longer exist on the remote. Tags are not subject to pruning if they
102           are fetched only because of the default tag auto-following or due
103           to a --tags option. However, if tags are fetched due to an explicit
104           refspec (either on the command line or in the remote configuration,
105           for example if the remote was cloned with the --mirror option),
106           then they are also subject to pruning. Supplying --prune-tags is a
107           shorthand for providing the tag refspec.
108
109           See the PRUNING section below for more details.
110
111       -P, --prune-tags
112           Before fetching, remove any local tags that no longer exist on the
113           remote if --prune is enabled. This option should be used more
114           carefully, unlike --prune it will remove any local references
115           (local tags) that have been created. This option is a shorthand for
116           providing the explicit tag refspec along with --prune, see the
117           discussion about that in its documentation.
118
119           See the PRUNING section below for more details.
120
121       -n, --no-tags
122           By default, tags that point at objects that are downloaded from the
123           remote repository are fetched and stored locally. This option
124           disables this automatic tag following. The default behavior for a
125           remote may be specified with the remote.<name>.tagOpt setting. See
126           git-config(1).
127
128       --refmap=<refspec>
129           When fetching refs listed on the command line, use the specified
130           refspec (can be given more than once) to map the refs to
131           remote-tracking branches, instead of the values of remote.*.fetch
132           configuration variables for the remote repository. See section on
133           "Configured Remote-tracking Branches" for details.
134
135       -t, --tags
136           Fetch all tags from the remote (i.e., fetch remote tags refs/tags/*
137           into local tags with the same name), in addition to whatever else
138           would otherwise be fetched. Using this option alone does not
139           subject tags to pruning, even if --prune is used (though tags may
140           be pruned anyway if they are also the destination of an explicit
141           refspec; see --prune).
142
143       --recurse-submodules[=yes|on-demand|no]
144           This option controls if and under what conditions new commits of
145           populated submodules should be fetched too. It can be used as a
146           boolean option to completely disable recursion when set to no or to
147           unconditionally recurse into all populated submodules when set to
148           yes, which is the default when this option is used without any
149           value. Use on-demand to only recurse into a populated submodule
150           when the superproject retrieves a commit that updates the
151           submodule’s reference to a commit that isn’t already in the local
152           submodule clone.
153
154       -j, --jobs=<n>
155           Number of parallel children to be used for fetching submodules.
156           Each will fetch from different submodules, such that fetching many
157           submodules will be faster. By default submodules will be fetched
158           one at a time.
159
160       --no-recurse-submodules
161           Disable recursive fetching of submodules (this has the same effect
162           as using the --recurse-submodules=no option).
163
164       --submodule-prefix=<path>
165           Prepend <path> to paths printed in informative messages such as
166           "Fetching submodule foo". This option is used internally when
167           recursing over submodules.
168
169       --recurse-submodules-default=[yes|on-demand]
170           This option is used internally to temporarily provide a
171           non-negative default value for the --recurse-submodules option. All
172           other methods of configuring fetch’s submodule recursion (such as
173           settings in gitmodules(5) and git-config(1)) override this option,
174           as does specifying --[no-]recurse-submodules directly.
175
176       -u, --update-head-ok
177           By default git fetch refuses to update the head which corresponds
178           to the current branch. This flag disables the check. This is purely
179           for the internal use for git pull to communicate with git fetch,
180           and unless you are implementing your own Porcelain you are not
181           supposed to use it.
182
183       --upload-pack <upload-pack>
184           When given, and the repository to fetch from is handled by git
185           fetch-pack, --exec=<upload-pack> is passed to the command to
186           specify non-default path for the command run on the other end.
187
188       -q, --quiet
189           Pass --quiet to git-fetch-pack and silence any other internally
190           used git commands. Progress is not reported to the standard error
191           stream.
192
193       -v, --verbose
194           Be verbose.
195
196       --progress
197           Progress status is reported on the standard error stream by default
198           when it is attached to a terminal, unless -q is specified. This
199           flag forces progress status even if the standard error stream is
200           not directed to a terminal.
201
202       -o <option>, --server-option=<option>
203           Transmit the given string to the server when communicating using
204           protocol version 2. The given string must not contain a NUL or LF
205           character. When multiple --server-option=<option> are given, they
206           are all sent to the other side in the order listed on the command
207           line.
208
209       -4, --ipv4
210           Use IPv4 addresses only, ignoring IPv6 addresses.
211
212       -6, --ipv6
213           Use IPv6 addresses only, ignoring IPv4 addresses.
214
215       <repository>
216           The "remote" repository that is the source of a fetch or pull
217           operation. This parameter can be either a URL (see the section GIT
218           URLS below) or the name of a remote (see the section REMOTES
219           below).
220
221       <group>
222           A name referring to a list of repositories as the value of
223           remotes.<group> in the configuration file. (See git-config(1)).
224
225       <refspec>
226           Specifies which refs to fetch and which local refs to update. When
227           no <refspec>s appear on the command line, the refs to fetch are
228           read from remote.<repository>.fetch variables instead (see
229           CONFIGURED REMOTE-TRACKING BRANCHES below).
230
231           The format of a <refspec> parameter is an optional plus +, followed
232           by the source <src>, followed by a colon :, followed by the
233           destination ref <dst>. The colon can be omitted when <dst> is
234           empty. <src> is typically a ref, but it can also be a fully spelled
235           hex object name.
236
237           tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>; it
238           requests fetching everything up to the given tag.
239
240           The remote ref that matches <src> is fetched, and if <dst> is not
241           empty string, the local ref that matches it is fast-forwarded using
242           <src>. If the optional plus + is used, the local ref is updated
243           even if it does not result in a fast-forward update.
244
245               Note
246               When the remote branch you want to fetch is known to be rewound
247               and rebased regularly, it is expected that its new tip will not
248               be descendant of its previous tip (as stored in your
249               remote-tracking branch the last time you fetched). You would
250               want to use the + sign to indicate non-fast-forward updates
251               will be needed for such branches. There is no way to determine
252               or declare that a branch will be made available in a repository
253               with this behavior; the pulling user simply must know this is
254               the expected usage pattern for a branch.
255

GIT URLS

257       In general, URLs contain information about the transport protocol, the
258       address of the remote server, and the path to the repository. Depending
259       on the transport protocol, some of this information may be absent.
260
261       Git supports ssh, git, http, and https protocols (in addition, ftp, and
262       ftps can be used for fetching, but this is inefficient and deprecated;
263       do not use it).
264
265       The native transport (i.e. git:// URL) does no authentication and
266       should be used with caution on unsecured networks.
267
268       The following syntaxes may be used with them:
269
270       ·   ssh://[user@]host.xz[:port]/path/to/repo.git/
271
272       ·   git://host.xz[:port]/path/to/repo.git/
273
274       ·   http[s]://host.xz[:port]/path/to/repo.git/
275
276       ·   ftp[s]://host.xz[:port]/path/to/repo.git/
277
278       An alternative scp-like syntax may also be used with the ssh protocol:
279
280       ·   [user@]host.xz:path/to/repo.git/
281
282       This syntax is only recognized if there are no slashes before the first
283       colon. This helps differentiate a local path that contains a colon. For
284       example the local path foo:bar could be specified as an absolute path
285       or ./foo:bar to avoid being misinterpreted as an ssh url.
286
287       The ssh and git protocols additionally support ~username expansion:
288
289       ·   ssh://[user@]host.xz[:port]/~[user]/path/to/repo.git/
290
291       ·   git://host.xz[:port]/~[user]/path/to/repo.git/
292
293       ·   [user@]host.xz:/~[user]/path/to/repo.git/
294
295       For local repositories, also supported by Git natively, the following
296       syntaxes may be used:
297
298       ·   /path/to/repo.git/
299
300       ·   file:///path/to/repo.git/
301
302       These two syntaxes are mostly equivalent, except when cloning, when the
303       former implies --local option. See git-clone(1) for details.
304
305       When Git doesn’t know how to handle a certain transport protocol, it
306       attempts to use the remote-<transport> remote helper, if one exists. To
307       explicitly request a remote helper, the following syntax may be used:
308
309       ·   <transport>::<address>
310
311       where <address> may be a path, a server and path, or an arbitrary
312       URL-like string recognized by the specific remote helper being invoked.
313       See gitremote-helpers(1) for details.
314
315       If there are a large number of similarly-named remote repositories and
316       you want to use a different format for them (such that the URLs you use
317       will be rewritten into URLs that work), you can create a configuration
318       section of the form:
319
320                   [url "<actual url base>"]
321                           insteadOf = <other url base>
322
323
324       For example, with this:
325
326                   [url "git://git.host.xz/"]
327                           insteadOf = host.xz:/path/to/
328                           insteadOf = work:
329
330
331       a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be
332       rewritten in any context that takes a URL to be
333       "git://git.host.xz/repo.git".
334
335       If you want to rewrite URLs for push only, you can create a
336       configuration section of the form:
337
338                   [url "<actual url base>"]
339                           pushInsteadOf = <other url base>
340
341
342       For example, with this:
343
344                   [url "ssh://example.org/"]
345                           pushInsteadOf = git://example.org/
346
347
348       a URL like "git://example.org/path/to/repo.git" will be rewritten to
349       "ssh://example.org/path/to/repo.git" for pushes, but pulls will still
350       use the original URL.
351

REMOTES

353       The name of one of the following can be used instead of a URL as
354       <repository> argument:
355
356       ·   a remote in the Git configuration file: $GIT_DIR/config,
357
358       ·   a file in the $GIT_DIR/remotes directory, or
359
360       ·   a file in the $GIT_DIR/branches directory.
361
362       All of these also allow you to omit the refspec from the command line
363       because they each contain a refspec which git will use by default.
364
365   Named remote in configuration file
366       You can choose to provide the name of a remote which you had previously
367       configured using git-remote(1), git-config(1) or even by a manual edit
368       to the $GIT_DIR/config file. The URL of this remote will be used to
369       access the repository. The refspec of this remote will be used by
370       default when you do not provide a refspec on the command line. The
371       entry in the config file would appear like this:
372
373                   [remote "<name>"]
374                           url = <url>
375                           pushurl = <pushurl>
376                           push = <refspec>
377                           fetch = <refspec>
378
379
380       The <pushurl> is used for pushes only. It is optional and defaults to
381       <url>.
382
383   Named file in $GIT_DIR/remotes
384       You can choose to provide the name of a file in $GIT_DIR/remotes. The
385       URL in this file will be used to access the repository. The refspec in
386       this file will be used as default when you do not provide a refspec on
387       the command line. This file should have the following format:
388
389                   URL: one of the above URL format
390                   Push: <refspec>
391                   Pull: <refspec>
392
393
394       Push: lines are used by git push and Pull: lines are used by git pull
395       and git fetch. Multiple Push: and Pull: lines may be specified for
396       additional branch mappings.
397
398   Named file in $GIT_DIR/branches
399       You can choose to provide the name of a file in $GIT_DIR/branches. The
400       URL in this file will be used to access the repository. This file
401       should have the following format:
402
403                   <url>#<head>
404
405
406       <url> is required; #<head> is optional.
407
408       Depending on the operation, git will use one of the following refspecs,
409       if you don’t provide one on the command line. <branch> is the name of
410       this file in $GIT_DIR/branches and <head> defaults to master.
411
412       git fetch uses:
413
414                   refs/heads/<head>:refs/heads/<branch>
415
416
417       git push uses:
418
419                   HEAD:refs/heads/<head>
420
421

CONFIGURED REMOTE-TRACKING BRANCHES

423       You often interact with the same remote repository by regularly and
424       repeatedly fetching from it. In order to keep track of the progress of
425       such a remote repository, git fetch allows you to configure
426       remote.<repository>.fetch configuration variables.
427
428       Typically such a variable may look like this:
429
430           [remote "origin"]
431                   fetch = +refs/heads/*:refs/remotes/origin/*
432
433
434       This configuration is used in two ways:
435
436       ·   When git fetch is run without specifying what branches and/or tags
437           to fetch on the command line, e.g.  git fetch origin or git fetch,
438           remote.<repository>.fetch values are used as the refspecs—they
439           specify which refs to fetch and which local refs to update. The
440           example above will fetch all branches that exist in the origin
441           (i.e. any ref that matches the left-hand side of the value,
442           refs/heads/*) and update the corresponding remote-tracking branches
443           in the refs/remotes/origin/* hierarchy.
444
445       ·   When git fetch is run with explicit branches and/or tags to fetch
446           on the command line, e.g.  git fetch origin master, the <refspec>s
447           given on the command line determine what are to be fetched (e.g.
448           master in the example, which is a short-hand for master:, which in
449           turn means "fetch the master branch but I do not explicitly say
450           what remote-tracking branch to update with it from the command
451           line"), and the example command will fetch only the master branch.
452           The remote.<repository>.fetch values determine which
453           remote-tracking branch, if any, is updated. When used in this way,
454           the remote.<repository>.fetch values do not have any effect in
455           deciding what gets fetched (i.e. the values are not used as
456           refspecs when the command-line lists refspecs); they are only used
457           to decide where the refs that are fetched are stored by acting as a
458           mapping.
459
460       The latter use of the remote.<repository>.fetch values can be
461       overridden by giving the --refmap=<refspec> parameter(s) on the command
462       line.
463

PRUNING

465       Git has a default disposition of keeping data unless it’s explicitly
466       thrown away; this extends to holding onto local references to branches
467       on remotes that have themselves deleted those branches.
468
469       If left to accumulate, these stale references might make performance
470       worse on big and busy repos that have a lot of branch churn, and e.g.
471       make the output of commands like git branch -a --contains <commit>
472       needlessly verbose, as well as impacting anything else that’ll work
473       with the complete set of known references.
474
475       These remote-tracking references can be deleted as a one-off with
476       either of:
477
478           # While fetching
479           $ git fetch --prune <name>
480
481           # Only prune, don't fetch
482           $ git remote prune <name>
483
484
485       To prune references as part of your normal workflow without needing to
486       remember to run that, set fetch.prune globally, or remote.<name>.prune
487       per-remote in the config. See git-config(1).
488
489       Here’s where things get tricky and more specific. The pruning feature
490       doesn’t actually care about branches, instead it’ll prune local <→
491       remote-references as a function of the refspec of the remote (see
492       <refspec> and CONFIGURED REMOTE-TRACKING BRANCHES above).
493
494       Therefore if the refspec for the remote includes e.g.
495       refs/tags/*:refs/tags/*, or you manually run e.g. git fetch --prune
496       <name> "refs/tags/*:refs/tags/*" it won’t be stale remote tracking
497       branches that are deleted, but any local tag that doesn’t exist on the
498       remote.
499
500       This might not be what you expect, i.e. you want to prune remote
501       <name>, but also explicitly fetch tags from it, so when you fetch from
502       it you delete all your local tags, most of which may not have come from
503       the <name> remote in the first place.
504
505       So be careful when using this with a refspec like
506       refs/tags/*:refs/tags/*, or any other refspec which might map
507       references from multiple remotes to the same local namespace.
508
509       Since keeping up-to-date with both branches and tags on the remote is a
510       common use-case the --prune-tags option can be supplied along with
511       --prune to prune local tags that don’t exist on the remote, and
512       force-update those tags that differ. Tag pruning can also be enabled
513       with fetch.pruneTags or remote.<name>.pruneTags in the config. See git-
514       config(1).
515
516       The --prune-tags option is equivalent to having refs/tags/*:refs/tags/*
517       declared in the refspecs of the remote. This can lead to some seemingly
518       strange interactions:
519
520           # These both fetch tags
521           $ git fetch --no-tags origin 'refs/tags/*:refs/tags/*'
522           $ git fetch --no-tags --prune-tags origin
523
524
525       The reason it doesn’t error out when provided without --prune or its
526       config versions is for flexibility of the configured versions, and to
527       maintain a 1=1 mapping between what the command line flags do, and what
528       the configuration versions do.
529
530       It’s reasonable to e.g. configure fetch.pruneTags=true in ~/.gitconfig
531       to have tags pruned whenever git fetch --prune is run, without making
532       every invocation of git fetch without --prune an error.
533
534       Pruning tags with --prune-tags also works when fetching a URL instead
535       of a named remote. These will all prune tags not found on origin:
536
537           $ git fetch origin --prune --prune-tags
538           $ git fetch origin --prune 'refs/tags/*:refs/tags/*'
539           $ git fetch <url of origin> --prune --prune-tags
540           $ git fetch <url of origin> --prune 'refs/tags/*:refs/tags/*'
541
542

OUTPUT

544       The output of "git fetch" depends on the transport method used; this
545       section describes the output when fetching over the Git protocol
546       (either locally or via ssh) and Smart HTTP protocol.
547
548       The status of the fetch is output in tabular form, with each line
549       representing the status of a single ref. Each line is of the form:
550
551            <flag> <summary> <from> -> <to> [<reason>]
552
553
554       The status of up-to-date refs is shown only if the --verbose option is
555       used.
556
557       In compact output mode, specified with configuration variable
558       fetch.output, if either entire <from> or <to> is found in the other
559       string, it will be substituted with * in the other string. For example,
560       master -> origin/master becomes master -> origin/*.
561
562       flag
563           A single character indicating the status of the ref:
564
565           (space)
566               for a successfully fetched fast-forward;
567
568           +
569               for a successful forced update;
570
571           -
572               for a successfully pruned ref;
573
574           t
575               for a successful tag update;
576
577           *
578               for a successfully fetched new ref;
579
580           !
581               for a ref that was rejected or failed to update; and
582
583           =
584               for a ref that was up to date and did not need fetching.
585
586       summary
587           For a successfully fetched ref, the summary shows the old and new
588           values of the ref in a form suitable for using as an argument to
589           git log (this is <old>..<new> in most cases, and <old>...<new> for
590           forced non-fast-forward updates).
591
592       from
593           The name of the remote ref being fetched from, minus its
594           refs/<type>/ prefix. In the case of deletion, the name of the
595           remote ref is "(none)".
596
597       to
598           The name of the local ref being updated, minus its refs/<type>/
599           prefix.
600
601       reason
602           A human-readable explanation. In the case of successfully fetched
603           refs, no explanation is needed. For a failed ref, the reason for
604           failure is described.
605

EXAMPLES

607       ·   Update the remote-tracking branches:
608
609               $ git fetch origin
610
611           The above command copies all branches from the remote refs/heads/
612           namespace and stores them to the local refs/remotes/origin/
613           namespace, unless the branch.<name>.fetch option is used to specify
614           a non-default refspec.
615
616       ·   Using refspecs explicitly:
617
618               $ git fetch origin +pu:pu maint:tmp
619
620           This updates (or creates, as necessary) branches pu and tmp in the
621           local repository by fetching from the branches (respectively) pu
622           and maint from the remote repository.
623
624           The pu branch will be updated even if it is does not fast-forward,
625           because it is prefixed with a plus sign; tmp will not be.
626
627       ·   Peek at a remote’s branch, without configuring the remote in your
628           local repository:
629
630               $ git fetch git://git.kernel.org/pub/scm/git/git.git maint
631               $ git log FETCH_HEAD
632
633           The first command fetches the maint branch from the repository at
634           git://git.kernel.org/pub/scm/git/git.git and the second command
635           uses FETCH_HEAD to examine the branch with git-log(1). The fetched
636           objects will eventually be removed by git’s built-in housekeeping
637           (see git-gc(1)).
638

SECURITY

640       The fetch and push protocols are not designed to prevent one side from
641       stealing data from the other repository that was not intended to be
642       shared. If you have private data that you need to protect from a
643       malicious peer, your best option is to store it in another repository.
644       This applies to both clients and servers. In particular, namespaces on
645       a server are not effective for read access control; you should only
646       grant read access to a namespace to clients that you would trust with
647       read access to the entire repository.
648
649       The known attack vectors are as follows:
650
651        1. The victim sends "have" lines advertising the IDs of objects it has
652           that are not explicitly intended to be shared but can be used to
653           optimize the transfer if the peer also has them. The attacker
654           chooses an object ID X to steal and sends a ref to X, but isn’t
655           required to send the content of X because the victim already has
656           it. Now the victim believes that the attacker has X, and it sends
657           the content of X back to the attacker later. (This attack is most
658           straightforward for a client to perform on a server, by creating a
659           ref to X in the namespace the client has access to and then
660           fetching it. The most likely way for a server to perform it on a
661           client is to "merge" X into a public branch and hope that the user
662           does additional work on this branch and pushes it back to the
663           server without noticing the merge.)
664
665        2. As in #1, the attacker chooses an object ID X to steal. The victim
666           sends an object Y that the attacker already has, and the attacker
667           falsely claims to have X and not Y, so the victim sends Y as a
668           delta against X. The delta reveals regions of X that are similar to
669           Y to the attacker.
670

BUGS

672       Using --recurse-submodules can only fetch new commits in already
673       checked out submodules right now. When e.g. upstream added a new
674       submodule in the just fetched commits of the superproject the submodule
675       itself can not be fetched, making it impossible to check out that
676       submodule later without having to do a fetch again. This is expected to
677       be fixed in a future Git version.
678

SEE ALSO

680       git-pull(1)
681

GIT

683       Part of the git(1) suite
684
685
686
687Git 2.18.1                        05/14/2019                      GIT-FETCH(1)
Impressum