cannyboy
cannyboy

Reputation: 24426

Updating all repos in a folder?

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.

Upvotes: 21

Views: 17093

Answers (10)

matlads
matlads

Reputation: 114

This is an old question, but i would like to suggest using myrepos.

You have a lot of version control repositories. Sometimes you want to update them all at once. Or push out all your local changes. Myrepos provides a mr command, which is a tool to manage all your version control repositories.

cd repos
find . -type d -depth 1 -exec mr register {} \
mr update

Upvotes: 0

Will Fox
Will Fox

Reputation: 27

I don't see any fix for this in the given answers, but a great way to modify the selected answer in order to avoid pulling on "./" repo is to also set the mindepth value on find. The following expression solves the OP question while also removing the error experienced by the selected answer:

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

This works for most *nix systems and should work for mac.

Upvotes: 0

morristech
morristech

Reputation: 43

  1. cd into the parent directory of the repositories you would like to update
  2. Then run the following
find . -type d -depth 1 -exec git --git-dir={}/.git --work-tree=$PWD/{} pull origin \;

credits to Leo

Upvotes: 0

S.Spieker
S.Spieker

Reputation: 7385

With powershell you can do it like that:

Get-ChildItem -Recurse -Depth 2 -Force | 
Where-Object { $_.Mode -match "h" -and $_.FullName -like "*\.git" } |
ForEach-Object {
  cd $_.FullName
  cd ../
  git pull
  cd ../
}

This will go into each directory and look for a .git folder and just run git pull in each of these folders.

Upvotes: 5

Shital Shah
Shital Shah

Reputation: 68828

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
)

Upvotes: 8

eqfox
eqfox

Reputation: 97

gitfox is a tool to execute command on all subrepo

npm install gitfox -g

g pull

Upvotes: 3

Melvin Columna
Melvin Columna

Reputation: 61

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.

Upvotes: 6

vonbrand
vonbrand

Reputation: 11831

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

Upvotes: 0

Ruslan Osipov
Ruslan Osipov

Reputation: 5843

Try this:

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

Upvotes: 37

wmfairuz
wmfairuz

Reputation: 1043

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.

Upvotes: 0

Related Questions