]> git.ipfire.org Git - thirdparty/git.git/blame - Documentation/git-fetch.txt
Merge branch 'ea/blame-use-oideq'
[thirdparty/git.git] / Documentation / git-fetch.txt
CommitLineData
215a7ad1
JH
1git-fetch(1)
2============
0c04094b
JH
3
4NAME
5----
c3f0baac 6git-fetch - Download objects and refs from another repository
0c04094b
JH
7
8
9SYNOPSIS
10--------
7791a1d9 11[verse]
e3163c75 12'git fetch' [<options>] [<repository> [<refspec>...]]
e3163c75 13'git fetch' [<options>] <group>
0adda936 14'git fetch' --multiple [<options>] [(<repository> | <group>)...]
e3163c75 15'git fetch' --all [<options>]
9c4a036b 16
0c04094b
JH
17
18DESCRIPTION
19-----------
53284560 20Fetch branches and/or tags (collectively, "refs") from one or more
366a0184
MB
21other repositories, along with the objects necessary to complete their
22histories. Remote-tracking branches are updated (see the description
23of <refspec> below for ways to control this behavior).
0c04094b 24
53284560
JH
25By default, any tag that points into the histories being fetched is
26also fetched; the effect is to fetch tags that
37f0dcbd 27point at branches that you are interested in. This default behavior
53284560 28can be changed by using the --tags or --no-tags options or by
da0005b8 29configuring remote.<name>.tagOpt. By using a refspec that fetches tags
53284560
JH
30explicitly, you can fetch tags that do not point into branches you
31are interested in as well.
02f571c7 32
366a0184 33'git fetch' can fetch from either a single named repository or URL,
9c4a036b
BG
34or from several repositories at once if <group> is given and
35there is a remotes.<group> entry in the configuration file.
36(See linkgit:git-config[1]).
0c04094b 37
379484b5
FC
38When no remote is specified, by default the `origin` remote will be used,
39unless there's an upstream branch configured for the current branch.
40
366a0184
MB
41The names of refs that are fetched, together with the object names
42they point at, are written to `.git/FETCH_HEAD`. This information
43may be used by scripts or other git commands, such as linkgit:git-pull[1].
44
0c04094b
JH
45OPTIONS
46-------
93d69d86 47include::fetch-options.txt[]
0c04094b 48
93d69d86 49include::pull-fetch-param.txt[]
d6a73596 50
2b713c27
JT
51--stdin::
52 Read refspecs, one per line, from stdin in addition to those provided
53 as arguments. The "tag <name>" format is not supported.
54
37ba0561 55include::urls-remotes.txt[]
0c04094b 56
d504f697 57
db4e4113
MB
58CONFIGURED REMOTE-TRACKING BRANCHES[[CRTB]]
59-------------------------------------------
fcb14b0c
JH
60
61You often interact with the same remote repository by
62regularly and repeatedly fetching from it. In order to keep track
63of the progress of such a remote repository, `git fetch` allows you
64to configure `remote.<repository>.fetch` configuration variables.
65
66Typically such a variable may look like this:
67
68------------------------------------------------
69[remote "origin"]
70 fetch = +refs/heads/*:refs/remotes/origin/*
71------------------------------------------------
72
73This configuration is used in two ways:
74
75* When `git fetch` is run without specifying what branches
76 and/or tags to fetch on the command line, e.g. `git fetch origin`
77 or `git fetch`, `remote.<repository>.fetch` values are used as
3b19dba7 78 the refspecs--they specify which refs to fetch and which local refs
fcb14b0c
JH
79 to update. The example above will fetch
80 all branches that exist in the `origin` (i.e. any ref that matches
81 the left-hand side of the value, `refs/heads/*`) and update the
82 corresponding remote-tracking branches in the `refs/remotes/origin/*`
83 hierarchy.
84
85* When `git fetch` is run with explicit branches and/or tags
86 to fetch on the command line, e.g. `git fetch origin master`, the
87 <refspec>s given on the command line determine what are to be
88 fetched (e.g. `master` in the example,
89 which is a short-hand for `master:`, which in turn means
90 "fetch the 'master' branch but I do not explicitly say what
91 remote-tracking branch to update with it from the command line"),
92 and the example command will
93 fetch _only_ the 'master' branch. The `remote.<repository>.fetch`
94 values determine which
95 remote-tracking branch, if any, is updated. When used in this
96 way, the `remote.<repository>.fetch` values do not have any
97 effect in deciding _what_ gets fetched (i.e. the values are not
98 used as refspecs when the command-line lists refspecs); they are
99 only used to decide _where_ the refs that are fetched are stored
100 by acting as a mapping.
101
c5558f80
JH
102The latter use of the `remote.<repository>.fetch` values can be
103overridden by giving the `--refmap=<refspec>` parameter(s) on the
104command line.
105
2c72ed74
ÆAB
106PRUNING
107-------
108
109Git has a default disposition of keeping data unless it's explicitly
110thrown away; this extends to holding onto local references to branches
111on remotes that have themselves deleted those branches.
112
113If left to accumulate, these stale references might make performance
114worse on big and busy repos that have a lot of branch churn, and
115e.g. make the output of commands like `git branch -a --contains
116<commit>` needlessly verbose, as well as impacting anything else
117that'll work with the complete set of known references.
118
119These remote-tracking references can be deleted as a one-off with
120either of:
121
122------------------------------------------------
123# While fetching
124$ git fetch --prune <name>
125
126# Only prune, don't fetch
127$ git remote prune <name>
128------------------------------------------------
129
130To prune references as part of your normal workflow without needing to
131remember to run that, set `fetch.prune` globally, or
132`remote.<name>.prune` per-remote in the config. See
133linkgit:git-config[1].
134
135Here's where things get tricky and more specific. The pruning feature
136doesn't actually care about branches, instead it'll prune local <->
137remote-references as a function of the refspec of the remote (see
138`<refspec>` and <<CRTB,CONFIGURED REMOTE-TRACKING BRANCHES>> above).
139
140Therefore if the refspec for the remote includes
141e.g. `refs/tags/*:refs/tags/*`, or you manually run e.g. `git fetch
142--prune <name> "refs/tags/*:refs/tags/*"` it won't be stale remote
143tracking branches that are deleted, but any local tag that doesn't
144exist on the remote.
145
146This might not be what you expect, i.e. you want to prune remote
147`<name>`, but also explicitly fetch tags from it, so when you fetch
148from it you delete all your local tags, most of which may not have
149come from the `<name>` remote in the first place.
150
151So be careful when using this with a refspec like
152`refs/tags/*:refs/tags/*`, or any other refspec which might map
153references from multiple remotes to the same local namespace.
154
97716d21
ÆAB
155Since keeping up-to-date with both branches and tags on the remote is
156a common use-case the `--prune-tags` option can be supplied along with
157`--prune` to prune local tags that don't exist on the remote, and
158force-update those tags that differ. Tag pruning can also be enabled
159with `fetch.pruneTags` or `remote.<name>.pruneTags` in the config. See
160linkgit:git-config[1].
161
162The `--prune-tags` option is equivalent to having
163`refs/tags/*:refs/tags/*` declared in the refspecs of the remote. This
164can lead to some seemingly strange interactions:
165
166------------------------------------------------
167# These both fetch tags
168$ git fetch --no-tags origin 'refs/tags/*:refs/tags/*'
169$ git fetch --no-tags --prune-tags origin
170------------------------------------------------
171
172The reason it doesn't error out when provided without `--prune` or its
173config versions is for flexibility of the configured versions, and to
174maintain a 1=1 mapping between what the command line flags do, and
175what the configuration versions do.
176
177It's reasonable to e.g. configure `fetch.pruneTags=true` in
178`~/.gitconfig` to have tags pruned whenever `git fetch --prune` is
179run, without making every invocation of `git fetch` without `--prune`
180an error.
181
6317972c
ÆAB
182Pruning tags with `--prune-tags` also works when fetching a URL
183instead of a named remote. These will all prune tags not found on
184origin:
97716d21
ÆAB
185
186------------------------------------------------
187$ git fetch origin --prune --prune-tags
6317972c
ÆAB
188$ git fetch origin --prune 'refs/tags/*:refs/tags/*'
189$ git fetch <url of origin> --prune --prune-tags
190$ git fetch <url of origin> --prune 'refs/tags/*:refs/tags/*'
97716d21
ÆAB
191------------------------------------------------
192
a52397cc
NTND
193OUTPUT
194------
195
196The output of "git fetch" depends on the transport method used; this
197section describes the output when fetching over the Git protocol
198(either locally or via ssh) and Smart HTTP protocol.
199
200The status of the fetch is output in tabular form, with each line
201representing the status of a single ref. Each line is of the form:
202
203-------------------------------
204 <flag> <summary> <from> -> <to> [<reason>]
205-------------------------------
206
207The status of up-to-date refs is shown only if the --verbose option is
208used.
209
bc437d10
NTND
210In compact output mode, specified with configuration variable
211fetch.output, if either entire `<from>` or `<to>` is found in the
212other string, it will be substituted with `*` in the other string. For
213example, `master -> origin/master` becomes `master -> origin/*`.
214
a52397cc
NTND
215flag::
216 A single character indicating the status of the ref:
217(space);; for a successfully fetched fast-forward;
218`+`;; for a successful forced update;
2cb040ba
NTND
219`-`;; for a successfully pruned ref;
220`t`;; for a successful tag update;
a52397cc
NTND
221`*`;; for a successfully fetched new ref;
222`!`;; for a ref that was rejected or failed to update; and
223`=`;; for a ref that was up to date and did not need fetching.
224
225summary::
226 For a successfully fetched ref, the summary shows the old and new
227 values of the ref in a form suitable for using as an argument to
228 `git log` (this is `<old>..<new>` in most cases, and
229 `<old>...<new>` for forced non-fast-forward updates).
230
231from::
232 The name of the remote ref being fetched from, minus its
233 `refs/<type>/` prefix. In the case of deletion, the name of
234 the remote ref is "(none)".
235
236to::
237 The name of the local ref being updated, minus its
238 `refs/<type>/` prefix.
239
240reason::
241 A human-readable explanation. In the case of successfully fetched
242 refs, no explanation is needed. For a failed ref, the reason for
243 failure is described.
fcb14b0c 244
d504f697
CB
245EXAMPLES
246--------
247
248* Update the remote-tracking branches:
249+
250------------------------------------------------
251$ git fetch origin
252------------------------------------------------
253+
254The above command copies all branches from the remote refs/heads/
255namespace and stores them to the local refs/remotes/origin/ namespace,
256unless the branch.<name>.fetch option is used to specify a non-default
257refspec.
258
259* Using refspecs explicitly:
260+
261------------------------------------------------
828197de 262$ git fetch origin +seen:seen maint:tmp
d504f697
CB
263------------------------------------------------
264+
828197de 265This updates (or creates, as necessary) branches `seen` and `tmp` in
d504f697 266the local repository by fetching from the branches (respectively)
828197de 267`seen` and `maint` from the remote repository.
d504f697 268+
828197de 269The `seen` branch will be updated even if it does not fast-forward,
d504f697
CB
270because it is prefixed with a plus sign; `tmp` will not be.
271
366a0184 272* Peek at a remote's branch, without configuring the remote in your local
ba170517 273 repository:
366a0184
MB
274+
275------------------------------------------------
276$ git fetch git://git.kernel.org/pub/scm/git/git.git maint
277$ git log FETCH_HEAD
278------------------------------------------------
279+
280The first command fetches the `maint` branch from the repository at
281`git://git.kernel.org/pub/scm/git/git.git` and the second command uses
282`FETCH_HEAD` to examine the branch with linkgit:git-log[1]. The fetched
283objects will eventually be removed by git's built-in housekeeping (see
284linkgit:git-gc[1]).
d504f697 285
235ec243
MM
286include::transfer-data-leaks.txt[]
287
794a3592
JL
288BUGS
289----
290Using --recurse-submodules can only fetch new commits in already checked
291out submodules right now. When e.g. upstream added a new submodule in the
6d169227 292just fetched commits of the superproject the submodule itself cannot be
794a3592 293fetched, making it impossible to check out that submodule later without
2de9b711 294having to do a fetch again. This is expected to be fixed in a future Git
794a3592
JL
295version.
296
fdd08979
JH
297SEE ALSO
298--------
5162e697 299linkgit:git-pull[1]
fdd08979 300
0c04094b
JH
301GIT
302---
9e1f0a85 303Part of the linkgit:git[1] suite