love
love

Reputation: 1040

How to change origin of multiple git repos?

I want to create multiple repositories inside one repository. These will be recursive. I already have a code of having 80-90 repositories. But i need to change the "origin" of each repository. So, i have two questions-

  1. How can i create git repositories recursively?

  2. (If .git is already present How can i change the "origin" of each repository?

Any help will be highly appreciated.

Upvotes: 1

Views: 218

Answers (2)

VonC
VonC

Reputation: 1324937

Note: using submodule would mean:

  • you can create your 80 repos independently of the main repo which will contain them: they can be hosted on (your disk/GitHub/GitLab/...)
  • you declare those repos as submodule, which means you are using the appropriate origin url when typing git submodule add:

    cd /path/to/main/repo
    git submodule add /url/to/submodule/repo
    

Then:

git submodule update --recursive --init

No need to change their origin after that.

That being said, if you still had to change their url, then, as commented by keltar:

git submodule foreach 'git remote set-url origin newremote.com:/path/to/git/dir/$path'

Upvotes: 1

nneonneo
nneonneo

Reputation: 179452

If you want to manage a bunch of repositories from a single repo, I suggest perhaps looking at the repo tool. Android uses this to manage the 100+ repositories that make up the Android Open Source Platform.

Upvotes: 0

Related Questions