Looping Through Subdirectories and Running a Command in Each

for dir in ~/projects/git/*; do (cd "$dir" && git pull); done

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


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