38

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.

Mark Fisher
  • 965
  • 1
  • 11
  • 30
Tony Scialo
  • 5,457
  • 11
  • 35
  • 52
  • 9
    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 – Tony Scialo Apr 14 '16 at 21:12

3 Answers3

45

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

Matias Elorriaga
  • 8,880
  • 5
  • 40
  • 58
  • 5
    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."* – wisbucky Apr 16 '18 at 18:22
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
CodeWizard
  • 128,036
  • 21
  • 144
  • 167
  • 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? – mfaani Jan 25 '19 at 20:56
  • @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. – Per Lundberg Jan 30 '19 at 11:13
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.

isherwood
  • 58,414
  • 16
  • 114
  • 157