blob: c718f7946f065d425c818c09bfd11fd641b73b4f [file] [log] [blame]
Junio C Hamano0c040942005-07-16 00:17:42 -07001<repository>::
Jon Loeligerbccf5952005-11-04 20:36:08 -06002 The "remote" repository that is the source of a fetch
John J. Franey58124732008-05-29 13:32:31 -04003 or pull operation. This parameter can be either a URL
4 (see the section <<URLS,GIT URLS>> below) or the name
5 of a remote (see the section <<REMOTES,REMOTES>> below).
Junio C Hamanoab9b3132005-08-24 16:23:08 -07006
Björn Gustavsson9c4a0362009-11-09 21:09:56 +01007ifndef::git-pull[]
8<group>::
9 A name referring to a list of repositories as the value
10 of remotes.<group> in the configuration file.
11 (See linkgit:git-config[1]).
12endif::git-pull[]
13
Junio C Hamanoab9b3132005-08-24 16:23:08 -070014<refspec>::
Marc Branchauddb4e4112014-06-11 10:24:04 -040015 Specifies which refs to fetch and which local refs to update.
16 When no <refspec>s appear on the command line, the refs to fetch
17 are read from `remote.<repository>.fetch` variables instead
18ifndef::git-pull[]
19 (see <<CRTB,CONFIGURED REMOTE-TRACKING BRANCHES>> below).
20endif::git-pull[]
21ifdef::git-pull[]
Philippe Blainf6a65de2020-04-05 15:50:18 +000022 (see the section "CONFIGURED REMOTE-TRACKING BRANCHES"
23 in linkgit:git-fetch[1]).
Marc Branchauddb4e4112014-06-11 10:24:04 -040024endif::git-pull[]
25+
26The format of a <refspec> parameter is an optional plus
Junio C Hamano83558a42017-10-17 11:31:06 +090027`+`, followed by the source <src>, followed
Marc Branchauddb4e4112014-06-11 10:24:04 -040028by a colon `:`, followed by the destination ref <dst>.
Junio C Hamano83558a42017-10-17 11:31:06 +090029The colon can be omitted when <dst> is empty. <src> is
30typically a ref, but it can also be a fully spelled hex object
31name.
Jonas Fonsecadf8baa42005-10-03 19:16:30 +020032+
Jacob Kellerc0192df2020-09-30 14:25:29 -070033A <refspec> may contain a `*` in its <src> to indicate a simple pattern
34match. Such a refspec functions like a glob that matches any ref with the
35same prefix. A pattern <refspec> must have a `*` in both the <src> and
36<dst>. It will map refs to the destination by replacing the `*` with the
37contents matched from the source.
38+
39If a refspec is prefixed by `^`, it will be interpreted as a negative
40refspec. Rather than specifying which refs to fetch or which local refs to
41update, such a refspec will instead specify refs to exclude. A ref will be
42considered to match if it matches at least one positive refspec, and does
43not match any negative refspec. Negative refspecs can be useful to restrict
44the scope of a pattern refspec so that it will not include specific refs.
45Negative refspecs can themselves be pattern refspecs. However, they may only
46contain a <src> and do not specify a <dst>. Fully spelled out hex object
47names are also not supported.
48+
Junio C Hamano5cc32682014-05-29 13:22:01 -070049`tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`;
50it requests fetching everything up to the given tag.
51+
J. Bruce Fields3598a302006-02-05 17:43:47 -050052The remote ref that matches <src>
Ævar Arnfjörð Bjarmasonae6a4702018-08-31 20:10:03 +000053is fetched, and if <dst> is not an empty string, an attempt
54is made to update the local ref that matches it.
55+
56Whether that update is allowed without `--force` depends on the ref
57namespace it's being fetched to, the type of object being fetched, and
58whether the update is considered to be a fast-forward. Generally, the
59same rules apply for fetching as when pushing, see the `<refspec>...`
60section of linkgit:git-push[1] for what those are. Exceptions to those
61rules particular to 'git fetch' are noted below.
62+
Ævar Arnfjörð Bjarmason0bc8d712018-08-31 20:10:04 +000063Until Git version 2.20, and unlike when pushing with
64linkgit:git-push[1], any updates to `refs/tags/*` would be accepted
Ævar Arnfjörð Bjarmason73e94792018-09-18 05:47:39 +000065without `+` in the refspec (or `--force`). When fetching, we promiscuously
Ævar Arnfjörð Bjarmason0bc8d712018-08-31 20:10:04 +000066considered all tag updates from a remote to be forced fetches. Since
Ævar Arnfjörð Bjarmason73e94792018-09-18 05:47:39 +000067Git version 2.20, fetching to update `refs/tags/*` works the same way
Ævar Arnfjörð Bjarmason0bc8d712018-08-31 20:10:04 +000068as when pushing. I.e. any updates will be rejected without `+` in the
69refspec (or `--force`).
Ævar Arnfjörð Bjarmasonae6a4702018-08-31 20:10:03 +000070+
71Unlike when pushing with linkgit:git-push[1], any updates outside of
72`refs/{tags,heads}/*` will be accepted without `+` in the refspec (or
73`--force`), whether that's swapping e.g. a tree object for a blob, or
Elijah Newrendbe33c52023-10-08 06:45:06 +000074a commit for another commit that doesn't have the previous commit as
Ævar Arnfjörð Bjarmasonae6a4702018-08-31 20:10:03 +000075an ancestor etc.
76+
Ævar Arnfjörð Bjarmason0bc8d712018-08-31 20:10:04 +000077Unlike when pushing with linkgit:git-push[1], there is no
78configuration which'll amend these rules, and nothing like a
79`pre-fetch` hook analogous to the `pre-receive` hook.
80+
Ævar Arnfjörð Bjarmasonae6a4702018-08-31 20:10:03 +000081As with pushing with linkgit:git-push[1], all of the rules described
82above about what's not allowed as an update can be overridden by
Elijah Newren0a4f0512023-10-08 06:45:17 +000083adding an optional leading `+` to a refspec (or using the `--force`
Ævar Arnfjörð Bjarmasonae6a4702018-08-31 20:10:03 +000084command line option). The only exception to this is that no amount of
85forcing will make the `refs/heads/*` namespace accept a non-commit
86object.
Jonas Fonsecadf8baa42005-10-03 19:16:30 +020087+
Jon Loeligerbccf5952005-11-04 20:36:08 -060088[NOTE]
Junio C Hamanof471dbc2014-05-29 12:53:28 -070089When the remote branch you want to fetch is known to
90be rewound and rebased regularly, it is expected that
Elijah Newren0a4f0512023-10-08 06:45:17 +000091its new tip will not be a descendant of its previous tip
Junio C Hamanof471dbc2014-05-29 12:53:28 -070092(as stored in your remote-tracking branch the last time
93you fetched). You would want
94to use the `+` sign to indicate non-fast-forward updates
95will be needed for such branches. There is no way to
96determine or declare that a branch will be made available
97in a repository with this behavior; the pulling user simply
Jon Loeligerbccf5952005-11-04 20:36:08 -060098must know this is the expected usage pattern for a branch.
Junio C Hamano5d59a322014-05-29 13:07:44 -070099ifdef::git-pull[]
Jon Loeligerbccf5952005-11-04 20:36:08 -0600100+
101[NOTE]
Junio C Hamanofdd08972005-11-05 01:37:00 -0800102There is a difference between listing multiple <refspec>
Thomas Rast0b444cd2010-01-10 00:33:00 +0100103directly on 'git pull' command line and having multiple
Junio C Hamano5d59a322014-05-29 13:07:44 -0700104`remote.<repository>.fetch` entries in your configuration
105for a <repository> and running a
Thomas Rast0b444cd2010-01-10 00:33:00 +0100106'git pull' command without any explicit <refspec> parameters.
Junio C Hamano5d59a322014-05-29 13:07:44 -0700107<refspec>s listed explicitly on the command line are always
Junio C Hamanofdd08972005-11-05 01:37:00 -0800108merged into the current branch after fetching. In other words,
Junio C Hamano5d59a322014-05-29 13:07:44 -0700109if you list more than one remote ref, 'git pull' will create
110an Octopus merge. On the other hand, if you do not list any
111explicit <refspec> parameter on the command line, 'git pull'
112will fetch all the <refspec>s it finds in the
113`remote.<repository>.fetch` configuration and merge
114only the first <refspec> found into the current branch.
115This is because making an
Junio C Hamanofdd08972005-11-05 01:37:00 -0800116Octopus from remote refs is rarely done, while keeping track
117of multiple remote heads in one-go by fetching more than one
118is often useful.
Junio C Hamano5d59a322014-05-29 13:07:44 -0700119endif::git-pull[]