threads / discuss / 64967

git fetch --dry-run can modify the repo

Subject: git fetch --dry-run can modify the repo

## tl;dr

2 messages between Feb 10, 2026 and Feb 10, 2026.

replies: 1people: 2as markdown or json

Tyler Breisacher· Feb 10, 2026, 05:33 UTC · lore

Interesting bug we came across -- or at least I think it's a bug. In any git repo that is not a shallow clone:

$ cat .git/shallow # "No such file or directory" $ git fetch --depth=1 --dry-run $ cat .git/shallow # Prints a git sha

I would think no command should make any changes to the local repo if --dry-run is passed.

Thanks!
Tyler
Jeff King· Feb 10, 2026, 07:50 UTC · re: Tyler Breisacher · lore

Re: git fetch --dry-run can modify the repo

On Mon, Feb 09, 2026 at 09:33:33PM -0800, Tyler Breisacher wrote:
Show 9 quoted lines
> Interesting bug we came across -- or at least I think it's a bug. In
> any git repo that is not a shallow clone:
> 
> $ cat .git/shallow # "No such file or directory"
> $ git fetch --depth=1 --dry-run
> $ cat .git/shallow # Prints a git sha
> 
> I would think no command should make any changes to the local repo if
> --dry-run is passed.
Here's a related thread with some more discussion:
  https://lore.kernel.org/git/CY8PR05MB100119985C7C25A72E530556DB517A@CY8PR05MB10011.namprd05.prod.outlook.com/

This is intended-ish, as --dry-run does still transfer objects, but just avoids updating any refs. And if we have shallow'd objects, we have to mark them as such (otherwise they appear corrupted).

There's some discussion in the thread above about whether a truly "dry" fetch would be a good idea. But short of that, probably the documentation could stand to be updated.

-Peff

← back to recent threads