| 1 | _<repository>_:: |
| 2 | The "remote" repository that is the source of a fetch |
| 3 | 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). |
| 6 | |
| 7 | ifndef::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]). |
| 12 | endif::git-pull[] |
| 13 | |
| 14 | [[fetch-refspec]] |
| 15 | _<refspec>_:: |
| 16 | Specifies which refs to fetch and which local refs to update. |
| 17 | When no __<refspec>__s appear on the command line, the refs to fetch |
| 18 | are read from `remote.<repository>.fetch` variables instead |
| 19 | ifndef::git-pull[] |
| 20 | (see <<CRTB,CONFIGURED REMOTE-TRACKING BRANCHES>> below). |
| 21 | endif::git-pull[] |
| 22 | ifdef::git-pull[] |
| 23 | (see the section "CONFIGURED REMOTE-TRACKING BRANCHES" |
| 24 | in linkgit:git-fetch[1]). |
| 25 | endif::git-pull[] |
| 26 | + |
| 27 | The format of a _<refspec>_ parameter is an optional plus |
| 28 | `+`, followed by the source _<src>_, followed |
| 29 | by a colon `:`, followed by the destination _<dst>_. |
| 30 | The colon can be omitted when _<dst>_ is empty. _<src>_ is |
| 31 | typically a ref, or a glob pattern with a single `*` that is used |
| 32 | to match a set of refs, but it can also be a fully spelled hex object |
| 33 | name. |
| 34 | + |
| 35 | A _<refspec>_ may contain a `*` in its _<src>_ to indicate a simple pattern |
| 36 | match. Such a refspec functions like a glob that matches any ref with the |
| 37 | pattern. A pattern _<refspec>_ must have one and only one `*` in both the _<src>_ and |
| 38 | _<dst>_. It will map refs to the destination by replacing the `*` with the |
| 39 | contents matched from the source. |
| 40 | + |
| 41 | If a refspec is prefixed by `^`, it will be interpreted as a negative |
| 42 | refspec. Rather than specifying which refs to fetch or which local refs to |
| 43 | update, such a refspec will instead specify refs to exclude. A ref will be |
| 44 | considered to match if it matches at least one positive refspec, and does |
| 45 | not match any negative refspec. Negative refspecs can be useful to restrict |
| 46 | the scope of a pattern refspec so that it will not include specific refs. |
| 47 | Negative refspecs can themselves be pattern refspecs. However, they may only |
| 48 | contain a _<src>_ and do not specify a _<dst>_. Fully spelled out hex object |
| 49 | names are also not supported. |
| 50 | + |
| 51 | `tag <tag>` means the same as `refs/tags/<tag>:refs/tags/<tag>`; |
| 52 | it requests fetching everything up to the given tag. |
| 53 | + |
| 54 | The remote ref that matches _<src>_ |
| 55 | is fetched, and if _<dst>_ is not an empty string, an attempt |
| 56 | is made to update the local ref that matches it. |
| 57 | + |
| 58 | Whether that update is allowed without `--force` depends on the ref |
| 59 | namespace it's being fetched to, the type of object being fetched, and |
| 60 | whether the update is considered to be a fast-forward. Generally, the |
| 61 | same rules apply for fetching as when pushing, see the `<refspec>...` |
| 62 | section of linkgit:git-push[1] for what those are. Exceptions to those |
| 63 | rules particular to `git fetch` are noted below. |
| 64 | + |
| 65 | Until Git version 2.20, and unlike when pushing with |
| 66 | linkgit:git-push[1], any updates to `refs/tags/*` would be accepted |
| 67 | without `+` in the refspec (or `--force`). When fetching, we promiscuously |
| 68 | considered all tag updates from a remote to be forced fetches. Since |
| 69 | Git version 2.20, fetching to update `refs/tags/*` works the same way |
| 70 | as when pushing. I.e. any updates will be rejected without `+` in the |
| 71 | refspec (or `--force`). |
| 72 | + |
| 73 | Unlike when pushing with linkgit:git-push[1], any updates outside of |
| 74 | `refs/{tags,heads}/*` will be accepted without `+` in the refspec (or |
| 75 | `--force`), whether that's swapping e.g. a tree object for a blob, or |
| 76 | a commit for another commit that doesn't have the previous commit as |
| 77 | an ancestor etc. |
| 78 | + |
| 79 | Unlike when pushing with linkgit:git-push[1], there is no |
| 80 | configuration which'll amend these rules, and nothing like a |
| 81 | `pre-fetch` hook analogous to the `pre-receive` hook. |
| 82 | + |
| 83 | As with pushing with linkgit:git-push[1], all of the rules described |
| 84 | above about what's not allowed as an update can be overridden by |
| 85 | adding an optional leading `+` to a refspec (or using the `--force` |
| 86 | command line option). The only exception to this is that no amount of |
| 87 | forcing will make the `refs/heads/*` namespace accept a non-commit |
| 88 | object. |
| 89 | + |
| 90 | [NOTE] |
| 91 | When the remote branch you want to fetch is known to |
| 92 | be rewound and rebased regularly, it is expected that |
| 93 | its new tip will not be a descendant of its previous tip |
| 94 | (as stored in your remote-tracking branch the last time |
| 95 | you fetched). You would want |
| 96 | to use the `+` sign to indicate non-fast-forward updates |
| 97 | will be needed for such branches. There is no way to |
| 98 | determine or declare that a branch will be made available |
| 99 | in a repository with this behavior; the pulling user simply |
| 100 | must know this is the expected usage pattern for a branch. |
| 101 | ifdef::git-pull[] |
| 102 | + |
| 103 | [NOTE] |
| 104 | There is a difference between listing multiple _<refspec>_ |
| 105 | directly on `git pull` command line and having multiple |
| 106 | `remote.<repository>.fetch` entries in your configuration |
| 107 | for a _<repository>_ and running a |
| 108 | `git pull` command without any explicit _<refspec>_ parameters. |
| 109 | __<refspec>__s listed explicitly on the command line are always |
| 110 | merged into the current branch after fetching. In other words, |
| 111 | if you list more than one remote ref, `git pull` will create |
| 112 | an Octopus merge. On the other hand, if you do not list any |
| 113 | explicit _<refspec>_ parameter on the command line, `git pull` |
| 114 | will fetch all the __<refspec>__s it finds in the |
| 115 | `remote.<repository>.fetch` configuration and merge |
| 116 | only the first _<refspec>_ found into the current branch. |
| 117 | This is because making an |
| 118 | Octopus from remote refs is rarely done, while keeping track |
| 119 | of multiple remote heads in one-go by fetching more than one |
| 120 | is often useful. |
| 121 | endif::git-pull[] |