1

I've got a couple of git repositories, each of them has several remotes named public_<user>.

I'd like to fetch simultaneously from every remote for all repositories.

I'd already discovered (myrepos) but this script only seams to work for origin remotes.

Onur
  • 5,017
  • 5
  • 38
  • 54

3 Answers3

3

The git remote update command will perform a fetch operation on all remotes for a given repository:

$ git remote
larsks
origin
$ git remote update
Fetching origin
remote: Reusing existing pack: 1, done.
remote: Total 1 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (1/1), done.
From https://github.com/teythoon/afew
   7317eb0..50db012  master     -> origin/master
Fetching larsks
From github.com:larsks/afew

If you wanted to automatically run this across a collection of git repositories, you could do something like this:

$ find * -maxdepth 1 -name .git -execdir git remote update \;

This finds everything containing a .git directory and then runs git remote update in the parent of the .git directory.

To find all bare repositories, you could do something like:

$ find * -maxdepth 1 -name index -execdir git remote update \;

That is, look for the index file instead of the .git directory.

If you wanted to target all submodules, you can use the git submodule foreach command:

$ find * -maxdepth 1 -name .git -execdir \
  git submodule foreach git remote update \;

If you wanted to combine this all into a single command:

$ find * -maxdepth 1 -name .git -execdir \
  sh -c 'git remote update; git submodule foreach git remote update' \;
larsks
  • 277,717
  • 41
  • 399
  • 399
2

I believe you're looking for the --all flag:

git fetch --all

Based on a quick glance at the script you linked, it seems like that script will accept this flag and pass it on to git for each of your repositories.

joshtkling
  • 3,428
  • 2
  • 18
  • 15
  • Is there a difference between `git fetch --all` and `git remote update`? Seams to me they both do the same. – Onur Mar 10 '14 at 14:02
  • As best I can tell, no. There's some discussion and history here: http://stackoverflow.com/questions/1856499/differences-between-git-remote-update-and-fetch – joshtkling Mar 10 '14 at 14:09
0

git forward fetches, prunes, and fast-forwards any number of tracking branches over any number of remotes at once. It's great for an integrator who's following many remotes/branches at once.

Wolf
  • 4,254
  • 1
  • 21
  • 30