-
Notifications
You must be signed in to change notification settings - Fork 7
Setting up a new git repo with two remotes
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 [email protected]:isse-augsburg/minibrass.git
cd minibrass
git remote -v
shall output:
origin [email protected]:isse-augsburg/minibrass.git (fetch)
origin [email protected]: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 ([email protected]:so/research-projects/minibrass/minibrass.git
):
git remote add gitlab [email protected]:so/research-projects/minibrass/minibrass.git
git remote -v
that will output
github [email protected]:isse-augsburg/minibrass.git (fetch)
github [email protected]:isse-augsburg/minibrass.git (push)
gitlab [email protected]:so/research-projects/minibrass/minibrass.git (fetch)
gitlab [email protected]: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 [email protected]:isse-augsburg/minibrass.git
git remote set-url --add --push all [email protected]:isse-augsburg/minibrass.git
git remote set-url --add --push all [email protected]:so/research-projects/minibrass/minibrass.git
That will give us the final setup:
git remote -v
all [email protected]:isse-augsburg/minibrass.git (fetch)
all [email protected]:isse-augsburg/minibrass.git (push)
all [email protected]:so/research-projects/minibrass/minibrass.git (push)
github [email protected]:isse-augsburg/minibrass.git (fetch)
github [email protected]:isse-augsburg/minibrass.git (push)
gitlab [email protected]:so/research-projects/minibrass/minibrass.git (fetch)
gitlab [email protected]: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