Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

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

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).

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

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

share|improve this answer

This should work

find . -maxdepth 1 -type d -name '.git' -exec sh -c 'cd "{}" && pwd && git pull' \;
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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