Skip to content

fetch: add fetch.shallow so pull doesn't fetch every branch on shallow repo - #2412

Open
HaraldNordgren wants to merge 1 commit into
git:masterfrom
HaraldNordgren:fetch-shallow-narrow-refspec
Open

HaraldNordgren wants to merge 1 commit into
git:masterfrom
HaraldNordgren:fetch-shallow-narrow-refspec

Conversation

@HaraldNordgren

@HaraldNordgren HaraldNordgren commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Add fetch.shallow config for big shallow repo, so git fetch/pull doesn't hang by fetching every branch.

@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit 040cd41:
fetch: add fetch.shallow so pull doesn't fetch every branch

  • Commit not signed off

@HaraldNordgren
HaraldNordgren force-pushed the fetch-shallow-narrow-refspec branch from 040cd41 to e7587fc Compare September 19, 2026 13:02
@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit e7587fc:
fetch: add fetch.shallow so pull doesn't fetch every branch

  • Commit not signed off

@HaraldNordgren
HaraldNordgren force-pushed the fetch-shallow-narrow-refspec branch from e7587fc to ab801c9 Compare September 19, 2026 13:14
@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit ab801c9:
fetch: add fetch.shallow so pull doesn't fetch every branch

  • Commit not signed off

@HaraldNordgren
HaraldNordgren force-pushed the fetch-shallow-narrow-refspec branch from ab801c9 to a518f40 Compare September 19, 2026 13:18
@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit a518f40:
fetch: add fetch.shallow so pull doesn't fetch every branch

  • Commit not signed off

@HaraldNordgren
HaraldNordgren force-pushed the fetch-shallow-narrow-refspec branch from a518f40 to 8916b1b Compare September 19, 2026 13:25
@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit 8916b1b:
fetch: add fetch.shallow so pull doesn't fetch every branch

  • Commit not signed off

@HaraldNordgren
HaraldNordgren force-pushed the fetch-shallow-narrow-refspec branch 2 times, most recently from 3df6357 to 7053e98 Compare September 19, 2026 13:34
@gitgitgadget-git

Copy link
Copy Markdown

There is an issue in commit 7053e98:
fetch: add fetch.shallow so pull doesn't fetch every branch

  • Commit not signed off

@HaraldNordgren
HaraldNordgren force-pushed the fetch-shallow-narrow-refspec branch 3 times, most recently from d6600e1 to 014dfde Compare September 19, 2026 13:47
@HaraldNordgren HaraldNordgren changed the title fetch: add fetch.shallow so pull doesn't fetch every branch fetch: add fetch.shallow so pull doesn't fetch every branch on shallow repo Sep 19, 2026
@HaraldNordgren
HaraldNordgren force-pushed the fetch-shallow-narrow-refspec branch from 014dfde to ec05d3e Compare September 19, 2026 13:56
@HaraldNordgren

Copy link
Copy Markdown
Contributor Author

/submit

@gitgitgadget-git

Copy link
Copy Markdown

Submitted as pull.2412.git.git.1789829246437.gitgitgadget@gmail.com

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2412/HaraldNordgren/fetch-shallow-narrow-refspec-v1

To fetch this version to local tag pr-git-2412/HaraldNordgren/fetch-shallow-narrow-refspec-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2412/HaraldNordgren/fetch-shallow-narrow-refspec-v1

In a shallow, sparsely checked out clone of a repository with many
branches, plain git pull can take minutes or hang outright, even
though only one branch is actually being worked on.

Add fetch.shallow, off by default. When enabled, a fetch or pull for
a shallow repository that isn't already scoped to specific refs
fetches only the current branch's tracked upstream and the remote's
default branch, instead of every branch the remote has. git pull
ultimately runs such a fetch under the hood, so this fixes pull the
same way. It has no effect once the repository is no longer shallow.

This is opt-in rather than automatic because it changes what a plain
fetch or pull leaves in refs/remotes/<name>/ for anyone who currently
relies on it syncing every branch of a shallow remote, not just the
one they are on. Scoping remote.<name>.fetch by hand already covers
this for a single remote, but that requires knowing the config exists
and applies it permanently, even to branches that are not currently
checked out.

The remote's recorded default branch (remotes/<name>/HEAD) is kept up
to date the same way it always is, only the other branches are
skipped. This works even on the very first fetch from a newly added
remote, before anything from it is tracked yet: the ls-refs
advertisement is narrowed to HEAD, and since the server tells us
directly which branch HEAD points to, that branch is fetched too and
written to refs/remotes/<name>/<branch>, so refs/remotes/<name>/HEAD
resolves correctly right away. Without this, git branch
--set-upstream-to=<remote> could not resolve a bare remote name until
either a full, unscoped fetch happened once, or git remote set-head
--auto was run by hand, both of which this config exists to avoid.

Signed-off-by: Harald Nordgren <haraldnordgren@gmail.com>
@HaraldNordgren
HaraldNordgren force-pushed the fetch-shallow-narrow-refspec branch from ec05d3e to 7586156 Compare September 19, 2026 16:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant