Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
up vote 56 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
Thnx... but i need to capture errors as well. How can I do so. I've never done shell programming before. – shashwat Feb 16 '15 at 10:37

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
-execdir is much better here: find . -type d -name .git -execdir sh -c "pwd && git pull" \; – daniel kullmann Jan 9 '12 at 7:51
This is a better answer in my subjective opinion... Worked immediately for me.. Cheers – Ransom Ani-Gizzle Jun 10 '15 at 14:30

If you have GNU Parallel http:// 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:

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .