Git add submodules to super project from existing repos
I have several (about 10-15) Git repositories in a directory:
~/plugins/admin
~/plugins/editor
~/plugins/etc
Each have their own separate repository and remote server.
The problem is that to pull all the changes from all the repositories I have to:
cd ~/plugins/admin
git pull origin master
password: ********
cd ..
cd ~/plugins/editor
git pull origin master
password: ********
cd ..
cd ~/plugins/etc
git pull origin开发者_StackOverflow master
password: ********
cd ..
How can I setup either Git submodules to pull all the repositories with 1 command,
OR alternatively write a script for Windows, Linux and Mac (as I use all 3 operating systems) to effectively do the same thing. Keeping in mind that the repos can be on different branches and don't necessarily have a tracking branch setup.
Same notes:
- The password is the same for all repos
- The remote server is the same repos (obviously in seperate repos/directories)
- I only want to type the password in once
- I only want to type one command to pull all repos
- Public/private keys are not an option
- I'm connecting to the remote via ssh
bash-3.2$ git submodule add git@repoUrl:SubmoduleName.git existing/submodule/path
Adding existing repo at 'existing/submodule/path' to the index
when you're trying to add submodule from place where some git repo already exists this repo will be added in index.
Use Perl, just as Git does. Assuming you have the password for each:
#!/usr/bin/perl
@dirs = ("admin", "editor", "etc" );
foreach(@dirs)
{
chdir($_);
exec( "git pull origin master" );
chdir("..");
}
With a little additional polish you could add better error handling and reading the password once, rather than each time.
(I know that this question very old, but maybe my reply will be useful for someone.)
Nowadays you can use git submodule foreach for such task.
And maybe git pull git pull --recurse-submodules=yes also can help you
精彩评论