Pregunta

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.

¿Fue útil?

Solución

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' \;

Otros consejos

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.

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top