git-fetch.txt 11 KB

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