Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/Documentation/git-fetch.adoc # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / Documentation / git-fetch.adoc` 318 lines ยท 11837 bytes Raw Blame History 1 git-fetch(1) 2 ============ 3 4 NAME 5 ---- 6 git-fetch - Download objects and refs from another repository 7 8 9 SYNOPSIS 10 -------- 11 [synopsis] 12 git fetch [] [ [...]] 13 git fetch [] 14 git fetch --multiple [] [(|)...] 15 git fetch --all [] 16 17 18 DESCRIPTION 19 ----------- 20 Fetch branches and/or tags (collectively, "refs") from one or more 21 other repositories, along with the objects necessary to complete their 22 histories. Remote-tracking branches are updated (see the description 23 of __ below for ways to control this behavior). 24 25 By default, any tag that points into the histories being fetched is 26 also fetched; the effect is to fetch tags that 27 point at branches that you are interested in. This default behavior 28 can be changed by using the `--tags` or `--no-tags` options or by 29 configuring `remote..tagOpt`. By using a refspec that fetches tags 30 explicitly, you can fetch tags that do not point into branches you 31 are interested in as well. 32 33 `git fetch` can fetch from either a single named repository or URL, 34 or from several repositories at once if __ is given and 35 there is a `remotes.` entry in the configuration file. 36 (See linkgit:git-config[1]). 37 38 When no remote is specified, by default the `origin` remote will be used, 39 unless there's an upstream branch configured for the current branch. 40 41 The names of refs that are fetched, together with the object names 42 they point at, are written to `.git/FETCH_HEAD`. This information 43 may be used by scripts or other git commands, such as linkgit:git-pull[1]. 44 45 OPTIONS 46 ------- 47 include::fetch-options.adoc[] 48 49 include::pull-fetch-param.adoc[] 50 51 `--stdin`:: 52 Read refspecs, one per line, from stdin in addition to those provided 53 as arguments. The "tag __" format is not supported. 54 55 include::urls-remotes.adoc[] 56 57 [[CRTB]] 58 CONFIGURED REMOTE-TRACKING BRANCHES 59 ----------------------------------- 60 61 You often interact with the same remote repository by 62 regularly and repeatedly fetching from it. In order to keep track 63 of the progress of such a remote repository, `git fetch` allows you 64 to configure `remote..fetch` configuration variables. 65 66 Typically such a variable may look like this: 67 68 ------------------------------------------------ 69 [remote "origin"] 70 fetch = +refs/heads/*:refs/remotes/origin/* 71 ------------------------------------------------ 72 73 This 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..fetch` values are used as 78 the refspecs--they specify which refs to fetch and which local refs 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 _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..fetch` 94 values determine which 95 remote-tracking branch, if any, is updated. When used in this 96 way, the `remote..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 102 The latter use of the `remote..fetch` values can be 103 overridden by giving the `--refmap=` parameter(s) on the 104 command line. 105 106 [[PRUNING]] 107 PRUNING 108 ------- 109 110 Git has a default disposition of keeping data unless it's explicitly 111 thrown away; this extends to holding onto local references to branches 112 on remotes that have themselves deleted those branches. 113 114 If left to accumulate, these stale references might make performance 115 worse on big and busy repos that have a lot of branch churn, and 116 e.g. make the output of commands like `git branch -a --contains 117 ` needlessly verbose, as well as impacting anything else 118 that'll work with the complete set of known references. 119 120 These remote-tracking references can be deleted as a one-off with 121 either of: 122 123 ------------------------------------------------ 124 # While fetching 125 $ git fetch --prune 126 127 # Only prune, don't fetch 128 $ git remote prune 129 ------------------------------------------------ 130 131 To prune references as part of your normal workflow without needing to 132 remember to run that, set `fetch.prune` globally, or 133 `remote..prune` per-remote in the config. See 134 linkgit:git-config[1]. 135 136 Here's where things get tricky and more specific. The pruning feature 137 doesn't actually care about branches, instead it'll prune local <--> 138 remote-references as a function of the refspec of the remote (see 139 `` and <> above). 140 141 Therefore if the refspec for the remote includes 142 e.g. `refs/tags/*:refs/tags/*`, or you manually run e.g. `git fetch 143 --prune "refs/tags/*:refs/tags/*"` it won't be stale remote 144 tracking branches that are deleted, but any local tag that doesn't 145 exist on the remote. 146 147 This might not be what you expect, i.e. you want to prune remote 148 __, but also explicitly fetch tags from it, so when you fetch 149 from it you delete all your local tags, most of which may not have 150 come from the __ remote in the first place. 151 152 So be careful when using this with a refspec like 153 `refs/tags/*:refs/tags/*`, or any other refspec which might map 154 references from multiple remotes to the same local namespace. 155 156 Since keeping up-to-date with both branches and tags on the remote is 157 a common use-case the `--prune-tags` option can be supplied along with 158 `--prune` to prune local tags that don't exist on the remote, and 159 force-update those tags that differ. Tag pruning can also be enabled 160 with `fetch.pruneTags` or `remote..pruneTags` in the config. See 161 linkgit:git-config[1]. 162 163 The `--prune-tags` option is equivalent to having 164 `refs/tags/*:refs/tags/*` declared in the refspecs of the remote. This 165 can lead to some seemingly strange interactions: 166 167 ------------------------------------------------ 168 # These both fetch tags 169 $ git fetch --no-tags origin 'refs/tags/*:refs/tags/*' 170 $ git fetch --no-tags --prune-tags origin 171 ------------------------------------------------ 172 173 The reason it doesn't error out when provided without `--prune` or its 174 config versions is for flexibility of the configured versions, and to 175 maintain a 1=1 mapping between what the command line flags do, and 176 what the configuration versions do. 177 178 It's reasonable to e.g. configure `fetch.pruneTags=true` in 179 `~/.gitconfig` to have tags pruned whenever `git fetch --prune` is 180 run, without making every invocation of `git fetch` without `--prune` 181 an error. 182 183 Pruning tags with `--prune-tags` also works when fetching a URL 184 instead of a named remote. These will all prune tags not found on 185 origin: 186 187 ------------------------------------------------ 188 $ git fetch origin --prune --prune-tags 189 $ git fetch origin --prune 'refs/tags/*:refs/tags/*' 190 $ git fetch --prune --prune-tags 191 $ git fetch --prune 'refs/tags/*:refs/tags/*' 192 ------------------------------------------------ 193 194 OUTPUT 195 ------ 196 197 The output of "git fetch" depends on the transport method used; this 198 section describes the output when fetching over the Git protocol 199 (either locally or via ssh) and Smart HTTP protocol. 200 201 The status of the fetch is output in tabular form, with each line 202 representing the status of a single ref. Each line is of the form: 203 204 ------------------------------- 205 -> [] 206 ------------------------------- 207 208 When using `--porcelain`, the output format is intended to be 209 machine-parseable. In contrast to the human-readable output formats it 210 thus prints to standard output instead of standard error. Each line is 211 of the form: 212 213 ------------------------------- 214 215 ------------------------------- 216 217 The status of up-to-date refs is shown only if the `--verbose` option is 218 used. 219 220 In compact output mode, specified with configuration variable 221 fetch.output, if either entire __ or __ is found in the 222 other string, it will be substituted with `*` in the other string. For 223 example, `master -> origin/master` becomes `master -> origin/*`. 224 225 flag:: 226 A single character indicating the status of the ref: 227 (space);; for a successfully fetched fast-forward; 228 `+`;; for a successful forced update; 229 `-`;; for a successfully pruned ref; 230 `t`;; for a successful tag update; 231 `*`;; for a successfully fetched new ref; 232 `!`;; for a ref that was rejected or failed to update; and 233 `=`;; for a ref that was up to date and did not need fetching. 234 235 summary:: 236 For a successfully fetched ref, the summary shows the old and new 237 values of the ref in a form suitable for using as an argument to 238 `git log` (this is `..` in most cases, and 239 `...` for forced non-fast-forward updates). 240 241 from:: 242 The name of the remote ref being fetched from, minus its 243 `refs//` prefix. In the case of deletion, the name of 244 the remote ref is "(none)". 245 246 to:: 247 The name of the local ref being updated, minus its 248 `refs//` prefix. 249 250 reason:: 251 A human-readable explanation. In the case of successfully fetched 252 refs, no explanation is needed. For a failed ref, the reason for 253 failure is described. 254 255 EXAMPLES 256 -------- 257 258 * Update the remote-tracking branches: 259 + 260 ------------------------------------------------ 261 $ git fetch origin 262 ------------------------------------------------ 263 + 264 The above command copies all branches from the remote `refs/heads/` 265 namespace and stores them to the local `refs/remotes/origin/` namespace, 266 unless the `remote..fetch` option is used to specify a 267 non-default refspec. 268 269 * Using refspecs explicitly: 270 + 271 ------------------------------------------------ 272 $ git fetch origin +seen:seen maint:tmp 273 ------------------------------------------------ 274 + 275 This updates (or creates, as necessary) branches `seen` and `tmp` in 276 the local repository by fetching from the branches (respectively) 277 `seen` and `maint` from the remote repository. 278 + 279 The `seen` branch will be updated even if it does not fast-forward, 280 because it is prefixed with a plus sign; `tmp` will not be. 281 282 * Peek at a remote's branch, without configuring the remote in your local 283 repository: 284 + 285 ------------------------------------------------ 286 $ git fetch git://git.kernel.org/pub/scm/git/git.git maint 287 $ git log FETCH_HEAD 288 ------------------------------------------------ 289 + 290 The first command fetches the `maint` branch from the repository at 291 `git://git.kernel.org/pub/scm/git/git.git` and the second command uses 292 `FETCH_HEAD` to examine the branch with linkgit:git-log[1]. The fetched 293 objects will eventually be removed by git's built-in housekeeping (see 294 linkgit:git-gc[1]). 295 296 include::transfer-data-leaks.adoc[] 297 298 CONFIGURATION 299 ------------- 300 301 include::includes/cmd-config-section-all.adoc[] 302 303 include::config/fetch.adoc[] 304 305 BUGS 306 ---- 307 Using `--recurse-submodules` can only fetch new commits in submodules that are 308 present locally e.g. in `$GIT_DIR/modules/`. If the upstream adds a new 309 submodule, that submodule cannot be fetched until it is cloned e.g. by `git 310 submodule update`. This is expected to be fixed in a future Git version. 311 312 SEE ALSO 313 -------- 314 linkgit:git-pull[1] 315 316 GIT 317 --- 318 Part of the linkgit:git[1] suite