GIT-FETCH(1)
๐ git-fetch(1) ๐
okay bestie, this is the Git Manual page for git-fetch, and itโs literally about downloading objects and refs from another repository. The vibe is fetching refs, updating remote-tracking branches, and writing .git/FETCH_HEAD. Letโs go ๐ซถ
๐ธ NAME ๐ธ
git-fetch โ Download objects and refs from another repository
โจ SYNOPSIS โจ
git fetch [<options>] [<repository> [<refspec>...]]
git fetch [<options>] <group>
git fetch --multiple [<options>] [(<repository>|<group>)...]
git fetch --all [<options>]
๐ DESCRIPTION ๐
Fetch branches and/or tags (collectively, refs) from one or more other repositories, along with the objects necessary to complete their histories. Remote-tracking branches are updated โ and yep, see the description of <refspec> below for ways to control this behavior. ๐
By default, any tag that points into the histories being fetched is also fetched; the effect is to fetch tags that point at branches that you are interested in. This default behavior can be changed by using the --tags or --no-tags options or by configuring remote.<name>.tagOpt. By using a refspec that fetches tags explicitly, you can fetch tags that do not point into branches you are interested in as well.
git fetch can fetch from either a single named repository or URL, or from several repositories at once if <group> is given and there is a remotes.<group> entry in the configuration file. (See git-config(1)).
When no remote is specified, by default the origin remote will be used, unless thereโs an upstream branch configured for the current branch.
The names of refs that are fetched, together with the object names they point at, are written to .git/FETCH_HEAD. This information may be used by scripts or other git commands, such as git-pull(1).
๐ OPTIONS ๐
okay so here come the flags, and bestie, there are so many. Every single one is iconic in its own way โจ
--all,--no-allโ Fetch all remotes, except for the ones that have theremote.<name>.skipFetchAllconfiguration variable set. This overrides the configuration variablefetch.all.-a,--appendโ Append ref names and object names of fetched refs to the existing contents of.git/FETCH_HEAD. Without this option old data in.git/FETCH_HEADwill be overwritten.--atomicโ Use an atomic transaction to update local refs. Either all refs are updated, or on error, no refs are updated. slay, itโs all-or-nothing.--depth=<depth>โ Limit fetching to the specified number of commits from the tip of each remote branch history. If fetching to a shallow repository created bygit clonewith--depth=<depth>option (seegit-clone(1)), deepen or shorten the history to the specified number of commits. Tags for the deepened commits are not fetched.--deepen=<depth>โ Similar to--depth, except it specifies the number of commits from the current shallow boundary instead of from the tip of each remote branch history.--shallow-since=<date>โ Deepen or shorten the history of a shallow repository to include all reachable commits after<date>.--shallow-exclude=<ref>โ Deepen or shorten the history of a shallow repository to exclude commits reachable from a specified remote branch or tag. This option can be specified multiple times.--unshallowโ If the source repository is complete, convert a shallow repository to a complete one, removing all the limitations imposed by shallow repositories.
If the source repository is shallow, fetch as much as possible so that the current repository has the same history as the source repository.
--update-shallowโ By default when fetching from a shallow repository,git fetchrefuses refs that require updating.git/shallow. This option updates.git/shallowand accepts such refs.--negotiation-restrict=(<commit>|<glob>),--negotiation-tip=(<commit>|<glob>)โ By default, Git will report, to the server, commits reachable from all local refs to find common commits in an attempt to reduce the size of the to-be-received packfile. If specified, Git will only report commits reachable from the given tips. This is useful to speed up fetches when the user knows which local ref is likely to have commits in common with the upstream ref being fetched.
--negotiation-restrict is the preferred name for this option; --negotiation-tip is accepted as a synonym.
This option may be specified more than once; if so, Git will report commits reachable from any of the given commits.
The argument to this option may be a glob on ref names, a ref, or the (possibly abbreviated) SHA-1 of a commit. Specifying a glob is equivalent to specifying this option multiple times, one for each matching ref name.
See also the fetch.negotiationAlgorithm and push.negotiate configuration variables documented in git-config(1), and the --negotiate-only option below.
--negotiation-include=(<commit>|<glob>)โ Ensure that the commits at the given tips are always sent as"have"lines during fetch negotiation, regardless of what the negotiation algorithm selects. This is useful to guarantee that common history reachable from specific refs is always considered, even when--negotiation-restrictrestricts the set of tips or when the negotiation algorithm would otherwise skip them.
This option may be specified more than once; if so, each commit is sent unconditionally.
The argument may be an exact ref name (e.g. refs/heads/release), an object hash, or a glob pattern (e.g. refs/heads/release/{asterisk}). The pattern syntax is the same as for --negotiation-restrict.
If --negotiation-restrict is used, the have set is first restricted by that option and then increased to include the tips specified by --negotiation-include.
If this option is not specified on the command line, then any remote.<name>.negotiationInclude config values for the current remote are used instead.
--negotiate-onlyโ Do not fetch anything from the server, and instead print the ancestors of the provided--negotiation-restrict=arguments, which we have in common with the server.
This is incompatible with --recurse-submodules=(yes|on-demand). Internally this is used to implement the push.negotiate option, see git-config(1).
--dry-runโ Show what would be done, without making any changes. look, no actual touching ๐--porcelainโ Print the output to standard output in an easy-to-parse format for scripts. See section OUTPUT ingit-fetch(1)for details.
This is incompatible with --recurse-submodules=(yes|on-demand) and takes precedence over the fetch.output config option.
--filter=<filter-spec>โ Use the partial clone feature and request that the server sends a subset of reachable objects according to a given object filter. When using--filter, the supplied<filter-spec>is used for the partial fetch.
If --filter=auto is used, the filter specification is determined automatically by combining the filter specifications advertised by the server for the promisor remotes that the client accepts (see gitprotocol-v2(5) and the promisor.acceptFromServer configuration option in git-config(1)).
For details on all other available filter specifications, see the --filter=<filter-spec> option in git-rev-list(1).
For example, --filter=blob:none will filter out all blobs (file contents) until needed by Git. Also, --filter=blob:limit=<size> will filter out all blobs of size at least <size>.
--write-fetch-head,--no-write-fetch-headโ Write the list of remote refs fetched in theFETCH_HEADfile directly under$GIT_DIR. This is the default. Passing--no-write-fetch-headfrom the command line tells Git not to write the file. Under--dry-runoption, the file is never written.-f,--forceโ Whengit fetchis used with<src>:<dst>refspec, it may refuse to update the local branch as discussed in the<refspec>part below. This option overrides that check.-k,--keepโ Keep downloaded pack.--multipleโ Allow several<repository>and<group>arguments to be specified. No<refspec>s may be specified.--auto-maintenance,--no-auto-maintenance,--auto-gc,--no-auto-gcโ Rungit maintenance run --autoat the end to perform automatic repository maintenance if needed. This is enabled by default.--write-commit-graph,--no-write-commit-graphโ Write a commit-graph after fetching. This overrides the config settingfetch.writeCommitGraph.--prefetchโ Modify the configured refspec to place all refs into therefs/prefetch/namespace. See theprefetchtask ingit-maintenance(1).-p,--pruneโ Before fetching, remove any remote-tracking references that no longer exist on the remote. Tags are not subject to pruning if they are fetched only because of the default tag auto-following or due to a--tagsoption. However, if tags are fetched due to an explicit refspec (either on the command line or in the remote configuration, for example if the remote was cloned with the--mirroroption), then they are also subject to pruning. Supplying--prune-tagsis a shorthand for providing the tag refspec.
See the PRUNING section below for more details.
-P,--prune-tagsโ Before fetching, remove any local tags that no longer exist on the remote if--pruneis enabled. This option should be used more carefully, unlike--pruneit will remove any local references (local tags) that have been created. This option is a shorthand for providing the explicit tag refspec along with--prune, see the discussion about that in its documentation.
See the PRUNING section below for more details.
-n,--no-tagsโ By default, tags that point at objects that are downloaded from the remote repository are fetched and stored locally. This option disables this automatic tag following. The default behavior for a remote may be specified with theremote.<name>.tagOptsetting. Seegit-config(1).--refetchโ Instead of negotiating with the server to avoid transferring commits and associated objects that are already present locally, this option fetches all objects as a fresh clone would. Use this to reapply a partial clone filter from configuration or using--filter=when the filter definition has changed. Automatic post-fetch maintenance will perform object database pack consolidation to remove any duplicate objects.--refmap=<refspec>โ ok so when you're fetching refs that you listed on the command line, this tells Git to use this refspec (and yeah, you can pass it more than once ๐ซถ) to map those refs onto your remote-tracking branches โ instead of using theremote.<name>.fetchconfig values for that remote repo. Sneaky useful detail: if you hand--refmapan empty<refspec>, Git straight-up ignores your configured refspecs and relies entirely on the ones you gave it on the command line. Full tea is in the "Configured Remote-tracking Branches" section. โจ-t,--tagsโ grab every tag from the remote (like, fetch remoterefs/tags/*into local tags with the same name), on top of whatever else you were already fetching. ๐ Important caveat bestie: using this option alone does not make tags get pruned, even if you're using--prune(though tags can still get pruned if they happen to also be the destination of an explicit refspec โ see--prune).--recurse-submodules[=(yes|on-demand|no)]โ controls whether (and when) new commits inside submodules get fetched too. When it recurses through submodules,git fetchalways tries to fetch "changed" submodules โ meaning a submodule that has commits referenced by a newly fetched superproject commit but that are missing from your local submodule clone. A changed submodule can be fetched as long as it's present locally, e.g. in$GIT_DIR/modules/(peepgitsubmodules(7)); but if upstream adds a new submodule, that one can't be fetched until it's cloned, e.g. bygit submodule update.
Setting it to on-demand fetches only changed submodules. Setting it to yes fetches all populated submodules, plus any submodules that are both unpopulated and changed. Setting it to no means submodules never get fetched, periodt. ๐ซ
When you don't specify it at all, it uses the value of fetch.recurseSubmodules if that's set (see git-config(1)), defaulting to on-demand if it isn't. And when you use this option with no value at all, it defaults to yes.
-j <n>,--jobs=<n>โ parallelize every form of fetching, up to<n>jobs at a time. โก A value of0uses some reasonable default (Git's choice, not yours ๐ ).
If you specified --multiple, the different remotes get fetched in parallel. If multiple submodules are being fetched, they get fetched in parallel too. Want to control them independently? Use the config settings fetch.parallel and submodule.fetchJobs (see git-config(1)).
Generally, parallel recursive and multi-remote fetches are faster. By default though, fetches are performed sequentially, not in parallel โ so this is your glow-up option. ๐ฅ
--no-recurse-submodulesโ turn off recursive submodule fetching (does the exact same thing as--recurse-submodules=no).--set-upstreamโ if the remote got fetched successfully, add the upstream (tracking) reference, which is what argument-lessgit-pull(1)and other commands use. More deets inbranch.<name>.mergeandbranch.<name>.remoteingit-config(1). ๐--submodule-prefix=<path>โ prepends<path>to paths printed in informative messages like"Fetching submodule foo". This one's used internally when recursing over submodules โ not your main character option, iykyk.--recurse-submodules-default=(yes|on-demand)โ used internally to temporarily provide a non-negative default value for the--recurse-submodulesoption. Note: all other methods of configuring fetch's submodule recursion (like settings ingitmodules(5)andgit-config(1)) override this option, and so does specifying--[no-]recurse-submodulesdirectly. So it's very much a "backup dancer" situation. ๐-u,--update-head-okโ by defaultgit fetchrefuses to update the head that corresponds to your current branch. This flag disables that check. ๐จ But like โ it's purely for internal use, sogit pullcan talk togit fetch. Unless you're out here implementing your own Porcelain, you are not supposed to use it. No cap.--upload-pack <upload-pack>โ when given, and the repo you're fetching from is handled bygit fetch-pack, then--exec=<upload-pack>gets passed to the command to specify a non-default path for the command that runs on the other end.-q,--quietโ pass--quiettogit-fetch-packand shush any other internally used git commands. Progress is not reported to the standard error stream. ๐คซ-v,--verboseโ be verbose. (That's it. That's the whole thing. Speak up bestie ๐ )--progressโ progress status is reported on the standard error stream by default when it's attached to a terminal, unless-qis specified. This flag forces progress status even when the standard error stream isn't pointed at a terminal. ๐ฆ-o <option>,--server-option=<option>โ transmits the given string to the server when communicating using protocol version 2. The string you give it must not contain aNULorLFcharacter. How the server handles server options (including unknown ones) is entirely server-specific โ not our problem, not our business. ๐ซ When you pass multiple--server-option=<option>, they all get sent to the other side in the order listed on the command line. And when you pass no--server-option=<option>on the command line at all, the values of the config variableremote.<name>.serverOptionare used instead.--show-forced-updatesโ by default, git checks whether a branch is force-updated during fetch. That can be turned off viafetch.showForcedUpdates, but the--show-forced-updatesoption guarantees this check happens. Seegit-config(1). โญ--no-show-forced-updatesโ by default, git checks whether a branch is force-updated during fetch. Pass--no-show-forced-updates, or setfetch.showForcedUpdatestofalse, to skip this check for performance reasons (yes, it's the speed-vs-safety tradeoff, pick your fighter ๐ญ). If you use this duringgit-pull, the--ff-onlyoption will still check for forced updates before attempting a fast-forward update. Seegit-config(1).-4,--ipv4โ use IPv4 addresses only, ignoring IPv6 addresses. ๐-6,--ipv6โ use IPv6 addresses only, ignoring IPv4 addresses. ๐
๐ the positional besties (yes they're still part of OPTIONS, we contain multitudes)
<repository>โ the "remote" repository that's the source of a fetch or pull operation. This parameter can be either a URL (see the section GIT URLS below) or the name of a remote (see the section REMOTES below).<group>โ a name that refers to a list of repositories, as the value ofremotes.<group>in the config file. (Seegit-config(1).)
๐ <refspec> โ the one that actually runs the show
Specifies which refs to fetch and which local refs to update. When no <refspec>s appear on the command line, the refs to fetch are read from remote.<repository>.fetch variables instead (see CONFIGURED REMOTE-TRACKING BRANCHES below).
The format of a <refspec> parameter is an optional plus +, followed by the source <src>, followed by a colon :, followed by the destination <dst>. The colon can be omitted when <dst> is empty. <src> is typically a ref, or a glob pattern with a single * that's used to match a set of refs โ but it can also be a fully spelled hex object name. ๐
A <refspec> may contain a * in its <src> to indicate a simple pattern match. Such a refspec functions like a glob that matches any ref with the pattern. A pattern <refspec> must have one and only one * in both the <src> and <dst>. It maps refs to the destination by replacing the * with the contents matched from the source.
If a refspec is prefixed by ^, it gets interpreted as a negative refspec. Rather than specifying which refs to fetch or which local refs to update, such a refspec instead specifies refs to exclude. A ref is considered to match if it matches at least one positive refspec and does not match any negative refspec. Negative refspecs are lowkey iconic for restricting the scope of a pattern refspec so it won't include specific refs. Negative refspecs can themselves be pattern refspecs โ however, they may only contain a <src> and do not specify a <dst>. Fully spelled out hex object names are also not supported. ๐ซ
tag <tag> means the same as refs/tags/<tag>:refs/tags/<tag>; it requests fetching everything up to the given tag.
The remote ref that matches <src> is fetched, and if <dst> isn't an empty string, an attempt is made to update the local ref that matches it.
Whether that update is allowed without --force depends on the ref namespace it's being fetched to, the type of object being fetched, and whether the update is considered to be a fast-forward. Generally, the same rules apply for fetching as when pushing โ see the <refspec>... section of git-push(1) for what those are. The exceptions particular to git fetch are noted below. ๐
- Until Git version 2.20, and unlike when pushing with
git-push(1), any updates torefs/tags/*would be accepted without+in the refspec (or--force). When fetching, we promiscuously considered all tag updates from a remote to be forced fetches. Since Git version 2.20, fetching to updaterefs/tags/*works the same way as when pushing. I.e. any updates will be rejected without+in the refspec (or--force). ๐ญ - Unlike when pushing with
git-push(1), any updates outside ofrefs/{tags,heads}/*will be accepted without+in the refspec (or--force) โ whether that's swapping e.g. a tree object for a blob, or a commit for another commit that doesn't have the previous commit as an ancestor, etc. - Unlike when pushing with
git-push(1), there is no configuration that'll amend these rules, and nothing like a pre-fetch hook analogous to thepre-receivehook.
As with pushing with git-push(1), all of the rules described above about what's not allowed as an update can be overridden by adding an optional leading + to a refspec (or using the --force command line option). The only exception to this is that no amount of forcing will make the refs/heads/* namespace accept a non-commit object. Like, at all. Don't even try. ๐
Note ๐ซถ When the remote branch you want to fetch is known to be rewound and rebased regularly, it's expected that its new tip will not be a descendant of its previous tip (as stored in your remote-tracking branch the last time you fetched). You'd want to use the + sign to indicate non-fast-forward updates will be needed for such branches. There is no way to determine or declare that a branch will be made available in a repository with this behavior; the pulling user simply must know this is the expected usage pattern for a branch. That's the vibe check you have to do manually, sadly. ๐
--stdinโ read refspecs, one per line, from stdin, in addition to the ones you provided as arguments. Heads up: the"tag <name>"format is not supported here. โจ
๐ GIT URLS ๐
okay so bestie, a URL is literally just the whole "where is this repo and how do I talk to it" situation ๐ In general, URLs contain info about the transport protocol, the address of the remote server, and the path to the repository. Depending on the transport protocol, some of this information may be absent โ no cap, sometimes it's just vibes and a path.
Git supports ssh, git, http, and https protocols. (also ftp and ftps can be used for fetching, but this is inefficient and deprecated; do not use them ๐)
โ ๏ธ the native transport (i.e. git:// URL) does no authentication and should be used with caution on unsecured networks. like, girl, be careful out there.
The following syntaxes may be used with them:
ssh://[<user>@]<host>[:<port>]/<path-to-git-repo>git://<host>[:<port>]/<path-to-git-repo>http[s]://<host>[:<port>]/<path-to-git-repo>ftp[s]://<host>[:<port>]/<path-to-git-repo>
An alternative scp-like syntax may also be used with the ssh protocol:
[<user>@]<host>:/<path-to-git-repo>
โจ heads up: this syntax is only recognized if there are no slashes before the first colon. This helps differentiate a local path that contains a colon. For example the local path foo:bar could be specified as an absolute path or ./foo:bar to avoid being misinterpreted as an ssh url. ikyk yk ๐
The ssh and git protocols additionally support ~<username> expansion:
ssh://[<user>@]<host>[:<port>]/~<user>/<path-to-git-repo>git://<host>[:<port>]/~<user>/<path-to-git-repo>[<user>@]<host>:~<user>/<path-to-git-repo>
For local repositories, also supported by Git natively, the following syntaxes may be used:
/path/to/repo.git/file:///path/to/repo.git/
These two syntaxes are mostly equivalent, except when cloning, when the former implies the --local option. See git-clone(1) for details ๐ซถ
git clone, git fetch and git pull, but not git push, will also accept a suitable bundle file. See git-bundle(1).
When Git doesn't know how to handle a certain transport protocol, it attempts to use the remote-<transport> remote helper, if one exists. To explicitly request a remote helper, the following syntax may be used:
<transport>::<address>
where <address> may be a path, a server and path, or an arbitrary URL-like string recognized by the specific remote helper being invoked. See gitremote-helpers(7) for details.
okay here's the cute part ๐ if there are a large number of similarly-named remote repositories and you want to use a different format for them (such that the URLs you use will be rewritten into URLs that work), you can create a configuration section of the form:
[url "<actual-url-base>"]
insteadOf = <other-url-base>
For example, with this:
[url "git://git.host.xz/"]
insteadOf = host.xz:/path/to/
insteadOf = work:
a URL like "work:repo.git" or like "host.xz:/path/to/repo.git" will be rewritten in any context that takes a URL to be "git://git.host.xz/repo.git". literally magic โจ
If you want to rewrite URLs for push only, you can create a configuration section of the form:
[url "<actual-url-base>"]
pushInsteadOf = <other-url-base>
For example, with this:
[url "ssh://example.org/"]
pushInsteadOf = git://example.org/
a URL like "git://example.org/path/to/repo.git" will be rewritten to "ssh://example.org/path/to/repo.git" for pushes, but pulls will still use the original URL. bestie gets the ssh treatment on the way out only ๐
๐ REMOTES ๐
The name of one of the following can be used instead of a URL as the <repository> argument:
- a remote in the Git configuration file:
$GIT_DIR/config, - a file in the
$GIT_DIR/remotesdirectory, or - a file in the
$GIT_DIR/branchesdirectory.
All of these also allow you to omit the refspec from the command line because they each contain a refspec which git will use by default. huge time-saver, obsessed ๐ญ
๐ Named remote in configuration file
You can choose to provide the name of a remote which you had previously configured using git-remote(1), git-config(1) or even by a manual edit to the $GIT_DIR/config file. The URL of this remote will be used to access the repository. The refspec of this remote will be used by default when you do not provide a refspec on the command line. The entry in the config file would appear like this:
[remote "<name>"]
url = <URL>
pushurl = <pushurl>
push = <refspec>
fetch = <refspec>
The <pushurl> is used for pushes only. It is optional and defaults to <URL>. Pushing to a remote affects all defined pushurls or all defined urls if no pushurls are defined. Fetch, however, will only fetch from the first defined url if multiple urls are defined. okay so push is an extrovert and fetch is a one-friend-at-a-time girlie ๐ฆ
๐ธ Named file in $GIT_DIR/remotes
You can choose to provide the name of a file in $GIT_DIR/remotes. The URL in this file will be used to access the repository. The refspec in this file will be used as default when you do not provide a refspec on the command line. This file should have the following format:
URL: one of the above URL formats
Push: <refspec>
Pull: <refspec>
Push: lines are used by git push and Pull: lines are used by git pull and git fetch. Multiple Push: and Pull: lines may be specified for additional branch mappings.
๐ Named file in $GIT_DIR/branches
You can choose to provide the name of a file in $GIT_DIR/branches. The URL in this file will be used to access the repository. This file should have the following format:
<URL>#<head>
<URL> is required; #<head> is optional.
Depending on the operation, git will use one of the following refspecs, if you don't provide one on the command line. <branch> is the name of this file in $GIT_DIR/branches and <head> defaults to master. yes girl, master, that's the default, don't come for me ๐
git fetch uses:
refs/heads/<head>:refs/heads/<branch>
git push uses:
HEAD:refs/heads/<head>
๐ UPSTREAM BRANCHES ๐
Branches in Git can optionally have an upstream remote branch. Git defaults to using the upstream branch for remote operations, for example:
- It's the default for
git pullorgit fetchwith no arguments. - It's the default for
git pushwith no arguments, with some exceptions. For example, you can use thebranch.<name>.pushRemoteoption to push to a different remote than you pull from, and by default withpush.default=simplethe upstream branch you configure must have the same name. - Various commands, including
git checkoutandgit status, will show you how many commits have been added to your current branch and the upstream since you forked from it, for example"Your branch and origin/main have diverged, and have 2 and 3 different commits each respectively".
The upstream is stored in .git/config, in the "remote" and "merge" fields. For example, if main's upstream is origin/main:
[branch "main"]
remote = origin
merge = refs/heads/main
You can set an upstream branch explicitly with git push --set-upstream <remote> <branch> but Git will often automatically set the upstream for you, for example:
- When you clone a repository, Git will automatically set the upstream for the default branch.
- If you have the
push.autoSetupRemoteconfiguration option set,git pushwill automatically set the upstream the first time you push a branch. - Checking out a remote-tracking branch with
git checkout <branch>will automatically create a local branch with that name and set the upstream to the remote branch.
Note ๐ Upstream branches are sometimes referred to as "tracking information", as in "set the branch's tracking information". same thing, different nickname, iykyk ๐
๐ฆ CONFIGURED REMOTE-TRACKING BRANCHES ๐ฆ
You often interact with the same remote repository by regularly and repeatedly fetching from it. In order to keep track of the progress of such a remote repository, git fetch allows you to configure remote.<repository>.fetch configuration variables. like, it's your little progress tracker, your roman empire, yourโ ๐ซถ
Typically such a variable may look like this:
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
This configuration is used in two ways:
- When
git fetchis run without specifying what branches and/or tags to fetch on the command line, e.g.git fetch originorgit fetch,remote.<repository>.fetchvalues are used as the refspecsโthey specify which refs to fetch and which local refs to update. The example above will fetch all branches that exist in theorigin(i.e. any ref that matches the left-hand side of the value,refs/heads/*) and update the corresponding remote-tracking branches in therefs/remotes/origin/*hierarchy. slay, it's doing all the work for you โจ - When
git fetchis run with explicit branches and/or tags to fetch on the command line, e.g.git fetch origin master, the<refspec>s given on the command line determine what are to be fetched (e.g.masterin the example, which is a short-hand formaster:, which in turn means "fetch themasterbranch but I do not explicitly say what remote-tracking branch to update with it from the command line"), and the example command will fetch only themasterbranch. Theremote.<repository>.fetchvalues determine which remote-tracking branch, if any, is updated. When used in this way, theremote.<repository>.fetchvalues do not have any effect in deciding what gets fetched (i.e. the values are not used as refspecs when the command-line lists refspecs); they are only used to decide where the refs that are fetched are stored by acting as a mapping. it's giving "I'm just the storage girlie, not the decision-maker" ๐
The latter use of the remote.<repository>.fetch values can be overridden by giving the --refmap=<refspec> parameter(s) on the command line. ๐ฅ
๐ธ PRUNING ๐ธ
Okay so bestie, here's the tea: Git's whole default vibe is keeping your data unless you literally throw it away. That energy extends to local references pointing at branches on remotes that have since deleted those branches. Git's just gonna sit there holding them ๐ซถ.
But if you let them pile up, those stale references can lowkey make performance worse on big, busy repos with a lot of branch churn โ and they'll make the output of things like git branch -a --contains <commit> needlessly verbose, plus they mess with anything else that works with the complete set of known references.
You can delete these remote-tracking references as a one-off with either of these:
# While fetching
$ git fetch --prune <name>
# Only prune, don't fetch
$ git remote prune <name>
And if you wanna prune as part of your normal workflow without having to remember to run that every time, set fetch.prune globally, or remote.<name>.prune per-remote in the config. See git-config(1).
Now here's where it gets tricky and more specific ๐. The pruning feature doesn't actually care about branches โ instead it prunes local โโ remote-references as a function of the refspec of the remote (see <refspec> and CONFIGURED REMOTE-TRACKING BRANCHES above).
So if the refspec for the remote includes, like, refs/tags/*:refs/tags/*, or you manually run something like git fetch --prune <name> "refs/tags/*:refs/tags/*", then it won't be stale remote tracking branches getting deleted โ it'll be any local tag that doesn't exist on the remote ๐ญ.
That might not be what you expect, i.e. you want to prune remote <name> but also explicitly fetch tags from it, so when you fetch from it you delete all your local tags โ most of which may not have come from the <name> remote in the first place. Yikes.
โ ๏ธ So be careful when using this with a refspec like refs/tags/*:refs/tags/*, or any other refspec which might map references from multiple remotes to the same local namespace. No cap, be careful.
Since keeping up-to-date with both branches and tags on the remote is a common use-case, the --prune-tags option can be supplied along with --prune to prune local tags that don't exist on the remote, and force-update those tags that differ. Tag pruning can also be enabled with fetch.pruneTags or remote.<name>.pruneTags in the config. See git-config(1).
The --prune-tags option is equivalent to having refs/tags/*:refs/tags/* declared in the refspecs of the remote. Which can lead to some seemingly strange interactions:
# These both fetch tags
$ git fetch --no-tags origin 'refs/tags/*:refs/tags/*'
$ git fetch --no-tags --prune-tags origin
The reason it doesn't error out when provided without --prune or its config versions is for flexibility of the configured versions, and to maintain a 1=1 mapping between what the command line flags do, and what the configuration versions do.
It's reasonable to e.g. configure fetch.pruneTags=true in ~/.gitconfig to have tags pruned whenever git fetch --prune is run, without making every invocation of git fetch without --prune an error. Slay ๐
.
Pruning tags with --prune-tags also works when fetching a URL instead of a named remote. These will all prune tags not found on origin:
$ git fetch origin --prune --prune-tags
$ git fetch origin --prune 'refs/tags/*:refs/tags/*'
$ git fetch <url-of-origin> --prune --prune-tags
$ git fetch <url-of-origin> --prune 'refs/tags/*:refs/tags/*'
โจ OUTPUT โจ
The output of git fetch depends on the transport method used; this section describes the output when fetching over the Git protocol (either locally or via ssh) and Smart HTTP protocol.
The status of the fetch is output in tabular form, with each line representing the status of a single ref. Each line is of the form:
<flag> <summary> <from> -> <to> [<reason>]
When using --porcelain, the output format is intended to be machine-parseable. In contrast to the human-readable output formats it thus prints to standard output instead of standard error. Each line is of the form:
<flag> <old-object-id> <new-object-id> <local-reference>
The status of up-to-date refs is shown only if the --verbose option is used.
In compact output mode, specified with configuration variable fetch.output, if either entire <from> or <to> is found in the other string, it will be substituted with * in the other string. For example, master -> origin/master becomes master -> origin/*. Cute, right? ๐
flag
A single character indicating the status of the ref:
(space)โ for a successfully fetched fast-forward;+โ for a successful forced update;-โ for a successfully pruned ref;tโ for a successful tag update;*โ for a successfully fetched new ref;!โ for a ref that was rejected or failed to update; and=โ for a ref that was up to date and did not need fetching.
summary
For a successfully fetched ref, the summary shows the old and new values of the ref in a form suitable for using as an argument to git log (this is <old>..<new> in most cases, and <old>...<new> for forced non-fast-forward updates).
from
The name of the remote ref being fetched from, minus its refs/<type>/ prefix. In the case of deletion, the name of the remote ref is "(none)".
to
The name of the local ref being updated, minus its refs/<type>/ prefix.
reason
A human-readable explanation. In the case of successfully fetched refs, no explanation is needed. For a failed ref, the reason for failure is described.
๐ EXAMPLES ๐
- Update the remote-tracking branches:
$ git fetch origin
The above command copies all branches from the remote refs/heads/ namespace and stores them to the local refs/remotes/origin/ namespace, unless the remote.<repository>.fetch option is used to specify a non-default refspec. Iconic behaviour honestly.
- Using refspecs explicitly:
$ git fetch origin +seen:seen maint:tmp
This updates (or creates, as necessary) branches seen and tmp in the local repository by fetching from the branches (respectively) seen and maint from the remote repository.
The seen branch will be updated even if it does not fast-forward, because it is prefixed with a plus sign; tmp will not be. That + is doing so much work ๐
.
- Peek at a remote's branch, without configuring the remote in your local repository:
$ git fetch git://git.kernel.org/pub/scm/git/git.git maint
$ git log FETCH_HEAD
The first command fetches the maint branch from the repository at git://git.kernel.org/pub/scm/git/git.git and the second command uses FETCH_HEAD to examine the branch with git-log(1). The fetched objects will eventually be removed by git's built-in housekeeping (see git-gc(1)).
๐ฆ SECURITY ๐ฆ
Real talk for a sec, bestie โ the fetch and push protocols are not designed to prevent one side from stealing data from the other repository that was not intended to be shared. If you have private data that you need to protect from a malicious peer, your best option is to store it in another repository. This applies to both clients and servers. In particular, namespaces on a server are not effective for read access control; you should only grant read access to a namespace to clients that you would trust with read access to the entire repository.
The known attack vectors are as follows:
- The victim sends "have" lines advertising the IDs of objects it has that are not explicitly intended to be shared but can be used to optimize the transfer if the peer also has them. The attacker chooses an object ID X to steal and sends a ref to X, but isn't required to send the content of X because the victim already has it. Now the victim believes that the attacker has X, and it sends the content of X back to the attacker later. (This attack is most straightforward for a client to perform on a server, by creating a ref to X in the namespace the client has access to and then fetching it. The most likely way for a server to perform it on a client is to "merge" X into a public branch and hope that the user does additional work on this branch and pushes it back to the server without noticing the merge.)
- As in #1, the attacker chooses an object ID X to steal. The victim sends an object Y that the attacker already has, and the attacker falsely claims to have X and not Y, so the victim sends Y as a delta against X. The delta reveals regions of X that are similar to Y to the attacker.
โ๏ธ CONFIGURATION โ๏ธ
Okay bestie, everything below this line in this section is selectively included from the git-config(1) documentation โ the content is literally the same as what's found there, no cap. ๐ซถ
fetch.recurseSubmodulesโ this one controls whethergit fetch(and the underlying fetch insidegit pull) will recursively fetch into populated submodules. You can set it to a boolean value or toon-demand. Setting a boolean flips the behavior of fetch and pull to recurse unconditionally into submodules whentrue, or to not recurse at all whenfalse. And when it's set toon-demand, fetch and pull will only recurse into a populated submodule when its superproject retrieves a commit that updates the submodule's reference. Defaults toon-demand, or to the value ofsubmodule.recurseif that's set. โจfetch.fsckObjectsโ if it's set totrue,git-fetch-packwill check all fetched objects. Peeptransfer.fsckObjectsfor what's actually checked. Defaults tofalse. And if it's not set, the value oftransfer.fsckObjectsis used instead. ๐fetch.fsck.<msg-id>โ acts likefsck.<msg-id>, but it's used bygit-fetch-pack(1)instead ofgit-fsck(1). See thefsck.<msg-id>documentation for the details, iykyk.fetch.fsck.skipListโ acts likefsck.skipList, but again it'sgit-fetch-pack(1)using it instead ofgit-fsck(1). See thefsck.skipListdocumentation for details.fetch.unpackLimitโ okay so if the number of objects fetched over the Git native transfer is below this limit, then the objects get unpacked into loose object files. But if the number of received objects equals or exceeds this limit, then the received pack will be stored as a pack, after adding any missing delta bases. Storing the pack from a push can make the push operation complete faster, especially on slow filesystems. If it's not set, the value oftransfer.unpackLimitis used instead. ๐ฆfetch.pruneโ iftrue, fetch will automatically behave as if the--pruneoption was given on the command line. See alsoremote.<name>.pruneand the PRUNING section ofgit-fetch(1). ๐งนfetch.pruneTagsโ iftrue, fetch will automatically behave as if therefs/tags/*:refs/tags/*refspec was provided when pruning, if it wasn't set already. This lets you set both this option andfetch.pruneto maintain a 1=1 mapping to upstream refs. See alsoremote.<name>.pruneTagsand the PRUNING section ofgit-fetch(1).fetch.allโ iftrue, fetch will attempt to update all available remotes. This behavior can be overridden by passing--no-allor by explicitly specifying one or more remote(s) to fetch from. Defaults tofalse. ๐fetch.outputโ controls how ref update status is printed. Valid values arefullandcompact. Default value isfull. See the OUTPUT section ingit-fetch(1)for details.fetch.negotiationAlgorithmโ controls how information about the commits in the local repository is sent when negotiating the contents of the packfile to be sent by the server. Set it toconsecutiveto use an algorithm that walks over consecutive commits checking each one. Set it toskippingto use an algorithm that skips commits in an effort to converge faster, but may result in a larger-than-necessary packfile; or set it tonoopto not send any information at all, which will almost certainly result in a larger-than-necessary packfile, but will skip the negotiation step. Set it todefaultto override settings made previously and use the default behaviour. The default is normallyconsecutive, but iffeature.experimentalis true, then the default isskipping. Unknown values will causegit fetchto error out. ๐ญ
See also the --negotiate-only and --negotiation-restrict options to git-fetch(1).
fetch.showForcedUpdatesโ set tofalseto enable--no-show-forced-updatesingit-fetch(1)andgit-pull(1)commands. Defaults totrue.fetch.parallelโ specifies the maximal number of fetch operations to be run in parallel at a time (submodules, or remotes when the--multipleoption ofgit-fetch(1)is in effect). โก
A value of 0 will give some reasonable default. If unset, it defaults to 1.
For submodules, this setting can be overridden using the submodule.fetchJobs config setting.
fetch.writeCommitGraphโ set totrueto write a commit-graph after everygit fetchcommand that downloads a pack-file from a remote. Using the--splitoption, most executions will create a very small commit-graph file on top of the existing commit-graph file(s). Occasionally, these files will merge and the write may take longer. Having an updated commit-graph file helps performance of many Git commands, includinggit merge-base,git push -f, andgit log --graph. Defaults tofalse. ๐fetch.bundleURIโ this value stores a URI for downloading Git object data from a bundle URI before performing an incremental fetch from the origin Git server. This is similar to how the--bundle-urioption behaves ingit-clone(1).git clone --bundle-uriwill set thefetch.bundleURIvalue if the supplied bundle URI contains a bundle list that is organized for incremental fetches. ๐
If you modify this value and your repository has a fetch.bundleCreationToken value, then remove that fetch.bundleCreationToken value before fetching from the new bundle URI. (Yes, really โ don't skip this step, bestie.)
fetch.bundleCreationTokenโ when usingfetch.bundleURIto fetch incrementally from a bundle list that uses the"creationToken"heuristic, this config value stores the maximumcreationTokenvalue of the downloaded bundles. This value is used to prevent downloading bundles in the future if the advertisedcreationTokenis not strictly larger than this value. ๐
The creation token values are chosen by the provider serving the specific bundle URI. If you modify the URI at fetch.bundleURI, then be sure to remove the value for the fetch.bundleCreationToken value before fetching.
fetch.followRemoteHEADโ when fetching using a default refspec, this setting determines how to handle differences between a fetched remote'sHEADand the localremotes/<name>/HEADsymbolic-ref. Its value is one of:createโ createremotes/<name>/HEADif a ref exists on the remote, but not locally. An existing symbolic-ref will not be touched. This is the default value. ๐warnโ display a warning if the remote advertises a differentHEADthan what is set locally. Behaves like"create"if the local symbolic-ref doesn't exist.alwaysโ silently updateremotes/<name>/HEADwhenever the remote advertises a new value.neverโ never create or modify theremotes/<name>/HEADsymbolic-ref.
๐ BUGS ๐
Okay listen โ using --recurse-submodules can only fetch new commits in submodules that are present locally, e.g. in $GIT_DIR/modules/. So if the upstream adds a new submodule, that submodule cannot be fetched until it is cloned, e.g. by git submodule update. This is expected to be fixed in a future Git version. Not us, not our fault, it's giving "known limitation" fr fr. ๐
๐ฆ SEE ALSO ๐ฆ
๐ GIT ๐
Part of the git(1) suite. ๐
That's the whole page, bestie โ you ate that. ๐ This gorgeousness is Git 2.56.0, dated 2026-09-27, and it's GIT-FETCH(1) in all its iconic glory. Go forth and fetch. ๐งโจ๐
๐ฆ where this page comes from
- arch rolling: git 2.56.0-1 ยท GPL-2.0-only
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms