tags:

views:

43

answers:

2

Hi,

How can I run

git pull origin master

on all sub directories of a directory.

I.E.

I have

/plugins/cms
/plugins/admin
/plugins/chart

etc and I want to update them all at the same time.

(Im running debian linux)

+3  A: 

This should happen automatically, so long as cms, admin and chart are all parts of the repository.

A likely issue is that each of these plugins is a git submodule.

Run git help submodule for more information.

EDIT

For doing this in bash:

cd plugins
for f in cms admin chart
do 
  cd $f && git pull origin master && cd ..
done
Jamie Wong
No, sorry you misunderstood. Each of those directories are a separate git repository. `/plugins` is not a repository
Petah
Ahhh. My mistake. Will give you the bash solution in a minute.
Jamie Wong
There you go. If you want to return to the parent directory, just run another `cd ..` afterwards.
Jamie Wong
Or use `pushd` and `popd` or put the group of commands in a subshell (when the subshell exits, you'll be left in the original directory). `(cd dir; for ... done)`
Dennis Williamson
Cool, that works. Now is there a way to pass the ssh password to the bash script and have the script pass it to git/ssh instead of prompting every time for my password?
Petah
Out of curiousity - why are aren't you using ssh keys instead?
Jamie Wong
A: 

If all of those directories are separate git repo, you should reference them as submodules.

That means your "origin" would be that remote repo 'plugins' which only contains references to subrepos 'cms', 'admin', 'chart'.

A git pull followed by a git submodule update would achieve what your are looking for.

VonC
See also http://stackoverflow.com/questions/1979167/git-submodule-update and http://stackoverflow.com/questions/1030169/git-easy-way-pull-latest-of-all-submodules: `git submodule foreach git pull` can also be of interest.
VonC
Note: to clarify, '`plugins`', which is not a git repo at the moment, should be made one, as a parent git repo for the submodules.
VonC