Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (29.3k points)
edited by

How can I update multiple git repositories from their shared parent's directory without cd'ing into each repo's root directory? I have the following which is all separate git repositories (not submodules):

/plugins/cms

/plugins/admin

/plugins/chart

I want to update them all at once or at least simplify my current workflow:

cd ~/plugins/admin

git pull origin master

cd ../chart

git pull

closed

1 Answer

0 votes
by (50.2k points)
selected by
 
Best answer

In this case, you need to run some plugins from your parent directory 

find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin master \;

find . will search for the current directory

-type d is used to find directories, not files

-depth 1 is used for a maximum depth of one sub-directory

-exec {} \; this runs a custom command for every find

Note: It would be better to use echo after -exec to preview.

eg.

 find . -type d -depth 1 -exec echo git --git-dir={}/.git --work-tree=$PWD/{} status \;

If the depth option is not found then use -mindepth 1 and -maxdepth 1.

Browse Categories

...