44

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.

1
  • 10
    the documentation you reference is confusing to a newer git command line user like myself. I was looking for a clear concise answer, which the other posters helped with greatly Commented Apr 14, 2016 at 21:12

4 Answers 4

52

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

Sign up to request clarification or add additional context in comments.

1 Comment

Also, git fetch by itself will use git fetch origin by default. From the docs: "When no remote is specified, by default the origin remote will be used, unless there’s an upstream branch configured for the current branch."
12
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

2 Comments

what do you mean by 'deleted data'? Do you mean if upstream removed an image, then by doing git fetch --all --prune the image would be removed from my local?
@Honey It means that local information about origin/some-branch etc will be deleted. It does not affect your working copy in any way, only your local copy of the remote repository.
6

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.

Comments

2

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.