Tony Scialo
Tony Scialo

Reputation: 5957

Git fetch origin vs git fetch --all

What is the difference between the following git commands?

git fetch origin

and

git fetch --all

Running them from the command line looks like they do the same thing.

Upvotes: 43

Views: 23232

Answers (4)

VonC
VonC

Reputation: 1323183

Normally, git fetch and git fetch origin are the same.
And they differ from git fetch --all, which fetches all the remotes.

But, with Git 2.44 (Q1 2024), "git fetch"(man) learned to pay attention to fetch.all configuration variable, which pretends as if "--all" was passed from the command line when no remote parameter was given.

See commit 39487a1 (08 Jan 2024) by Tamino Bauknecht (taminob).
(Merged by Junio C Hamano -- gitster -- in commit f033388, 19 Jan 2024)

fetch: add new config option fetch.all

Signed-off-by: Tamino Bauknecht

Introduce a boolean configuration option fetch.all which allows to fetch all available remotes by default.
The config option can be overridden by explicitly specifying a remote or by using --no-all.
The behavior for --all is unchanged and calling git-fetch(man) with --all and a remote will still result in an error.

Additionally, describe the configuration variable in the config documentation and implement new tests to cover the expected behavior.
Also add --no-all(man) to the command-line documentation of git-fetch.

git config now includes in its man page:

fetch.all

If true, fetch will attempt to update all available remotes. This behavior can be overridden by passing --no-all or by explicitly specifying one or more remote(s) to fetch from. Defaults to false.

fetch-options now includes in its man page:

--[no-]all

Fetch all remotes. This overrides the configuration variable fetch.all.

So... git fetch and git fetch --all could be the same(!) if git config fetch.all true was done first.

Upvotes: 2

CodeWizard
CodeWizard

Reputation: 141946

git fetch --all

--all
Fetch all remotes.

If you want to get all the data and on the same time also to remove the
deleted data add the --prune flag

# Fetch all data, remove dangling objects and pack you repository
git fetch --all --prune=now

Upvotes: 12

Matias Elorriaga
Matias Elorriaga

Reputation: 9150

git fetch origin fetch data only from origin, and git fetch --all fetch data from all remotes (origin is one of them)

Upvotes: 50

isherwood
isherwood

Reputation: 61056

Your repository may have one remote point known by alias as 'origin', but you may also have other remotes configured. The latter command would fetch from them all.

More in the docs for fetch.

Upvotes: 6

Related Questions