Skip to content

Setting up a new git repo with two remotes

Alexander Schiendorfer edited this page Dec 13, 2017 · 1 revision

For MiniBrass, we use two remote repositories, one here on github, and another one at Gitlab.isse.de which provides us with useful CI/CD facilities (running the unit tests, in particular).

That means, it's very convenient to set up our repository in a way that every push is automatically forwarded to two repositories:

Assuming you started by cloning the github repository:

git clone git@github.com:isse-augsburg/minibrass.git
cd minibrass
git remote -v

shall output:

origin	git@github.com:isse-augsburg/minibrass.git (fetch)
origin	git@github.com:isse-augsburg/minibrass.git (push)

Now, we need to add the second (gitlab) repo and follow the explanations at https://stackoverflow.com/questions/14290113/git-pushing-code-to-two-remotes

First, let us rename the github repo from origin to github:

git remote rename origin github

and add a new remote to gitlab (git@gitlab.isse.de:so/research-projects/minibrass/minibrass.git):

git remote add gitlab git@gitlab.isse.de:so/research-projects/minibrass/minibrass.git
git remote -v

that will output

github	git@github.com:isse-augsburg/minibrass.git (fetch)
github	git@github.com:isse-augsburg/minibrass.git (push)
gitlab	git@gitlab.isse.de:so/research-projects/minibrass/minibrass.git (fetch)
gitlab	git@gitlab.isse.de:so/research-projects/minibrass/minibrass.git (push)

Next, we add a new remote all that will act on behalf of both remotes (using two pushurls)

git remote add all git@github.com:isse-augsburg/minibrass.git
git remote set-url --add --push all git@github.com:isse-augsburg/minibrass.git
git remote set-url --add --push all git@gitlab.isse.de:so/research-projects/minibrass/minibrass.git

That will give us the final setup:

git remote -v
all	git@github.com:isse-augsburg/minibrass.git (fetch)
all	git@github.com:isse-augsburg/minibrass.git (push)
all	git@gitlab.isse.de:so/research-projects/minibrass/minibrass.git (push)
github	git@github.com:isse-augsburg/minibrass.git (fetch)
github	git@github.com:isse-augsburg/minibrass.git (push)
gitlab	git@gitlab.isse.de:so/research-projects/minibrass/minibrass.git (fetch)
gitlab	git@gitlab.isse.de:so/research-projects/minibrass/minibrass.git (push)

Finally, we can set the default upstream to all

git push -u all 

From then on, we only need to invoke git push

Clone this wiki locally
You can’t perform that action at this time.