up vote 2 down vote favorite
share [g+] share [fb]

I have a set of repositories sorted into directories based on their VCS (Git, Mercurial, SVN). With Subversion I was able to run svn update * in the parent directory and it would loop through each directory and update each repository as expected. That's not the case for Git or Mercurial.

I would like to come up with a bash script that I can run to do exactly that, loop through directories and either git pull or hg pull in each. I just don't have much bash scripting experience.

link|improve this question
feedback

3 Answers

up vote 3 down vote accepted
for dir in ~/projects/git/*
do
  (cd $dir && git pull)
done
link|improve this answer
Thank you! That worked perfectly. :) – Bryan Veloso Sep 21 '09 at 22:12
feedback

If you have GNU Parallel http:// www.gnu.org/software/parallel/ installed you can do this:

cd ~/projects/git/; ls | parallel 'cd {} && git pull'

This will run in parallel so if some of the git servers' network connection are slow this may speed up things.

Watch the intro video for GNU Parallel to learn more: http://www.youtube.com/watch?v=OpaiGYxkSuQ

link|improve this answer
feedback

If you need it to be recursive:

find . -type d -name .git -exec sh -c "cd \"{}\"/../ && pwd && git pull" \;

This will descend into all the directories under the current one, and perform a git pull on those subdirectories that have a .git directory (you can limit it with -maxdepth).

link|improve this answer
@thprivileges: clever! – Dennis Williamson Jan 6 at 21:41
-execdir is much better here: find . -type d -name .git -execdir sh -c "pwd && git pull" \; – daniel kullmann Jan 9 at 7:51
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.