Farhad Ahmed
Farhad Ahmed

Reputation: 65

Cloning two remote repos with the same data

I have a remote repo in GitHub and I have another remote in Heroku with the exact same data. I've started working through a new device and tried cloning both repos but can't find a simple way to do it. git clone [repo name] creates a new directory. So cloning from the second repo will be prevented it'll attempt to create a new directory of the same name. I could clone one repo, cd into it, and then clone the second one. But it isn't ideal since I then end up with one repo with another repo inside of it.

For example, if my pwd is Repositories/ and I do a git clone for GitHub I'd end up with Repositories/MyProject. If I then cd into it and try a git clone for the second repo I end up with Repositories/MyProject/Myproject.

Upvotes: 1

Views: 139

Answers (2)

VonC
VonC

Reputation: 1324937

git remote add [repo name]' creates a new directory

No it does not. git remote only modifies the local config of the current repo (the .git/config file).

git clone /url/first_repo
cd first_repo
git remote add second_repo /url/second_repo
git config --local -l
git fetch second_repo

Then you can see all branches from both repos:

git branch -avv

If you want to clone two repo, simply do so from the same root folder

cd afolder
git clone /url/repo1
git clone /url/repo2 adifferentName

Upvotes: 1

Sajib Khan
Sajib Khan

Reputation: 24176

Go to your Repositories/ directory. Then clone first one (git clone ...). Now go into first repo and add a new remote (git remote add <second> ).

$ cd Repositories
$ git clone <first-repo-url>

$ cd <first-repo>
$ git remote add <second> <second-repo-url>
$ git pull second master          # pull the second repo's master branch changes 

Upvotes: 1

Related Questions