Updating all repos in a folder?

2019-02-03 18:20发布

问题:

I've got a folder - 'Repos' - which contains the repos that I'm interested in. These have been cloned from bitbucket, but I guess github could be a source too.

Repos
    - music-app
    - elephant-site
    - node-demo

Is there a git command that I can use which steps thru every folder in Repos and sees if there are new commits on the server, and the download the new stuff? And if there are new commits locally, then upload these.

回答1:

Try this:

cd repos
find . -maxdepth 1 -type d -exec sh -c '(cd {} && git pull)' ';'


回答2:

For Windows, this should do it for you via a Command Prompt:

cd c:\repos
for /d %a in (*.*) do cd c:\repos\%a && git pull

Once you go back to the GitHub client, you should see the updates.



回答3:

gitfox is a tool to execute command on all subrepo

npm install gitfox -g

g pull



回答4:

To maintain several repos, you can use git submodule.

Use git submodule add to add a repo as a submodule and use git submodule foreach git pull to update the repos.

This method is like you have a super project, with several git projects in it.



回答5:

What I have is a scriptlet that does something like:

for d in *
cd $d
git pull
cd ..

(Yes, it has a few extra bells and whistles, in that I have a few hg repos, and others I manage in git from SVN upstream.)



回答6:

For Windows, I'm using below in .cmd file. It can easily be extended to do something more or something else:

for /d %%i in (*) do (
  pushd "%%i"
  git pull
  popd
)