Tutorials / Tech blog / Geek Zone

Latest Posts

Monday, August 27, 2018

Push :: To Multiple Repos Simultaneously

This tutorial helps demonstrate the process configuration to push your source code to multiple repositories.


Background

If a need arises to have multiple repos, then it's always better that they are in sync. Fortunately, Git allows pushing the source code to multiple repos at once.


Remote URL

Let's consider the following repo urls for the source code to be pushed. You can observe, the urls are almost identical except the domain name.

1
2
3
git@github.com:g33kzone/multi-repo.git

git@gitlab.com:g33kzone/multi-repo.git

Note : To prevent being asked for passwords while pushing the source code, make sure to set up SSH access for each service.

Let's have an alias created called origin to your main remote repository (i.e. Github)

1
git remote add origin git@github.com:g33kzone/multi-repo.git

Configure Push Remote URLs

Following commands (over the command line) will do the trick.

1
2
3
git remote set-url --add --push origin git@github.com:g33kzone/multi-repo.git

git remote set-url --add --push origin git@gitlab.com:g33kzone/multi-repo.git


This can be confirmed by running the following command

1
git remote show origin

Push Multiple Repos

Use the following command (over the command line - once) to set the upstream

1
git push --set-upstream origin master

Later only "git push" should also work.

No comments:

Post a Comment