DEV Community

Manish R Warang
Manish R Warang

Posted on • Originally published at blog.g33kzone.com on

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.

Git Multi Repo

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.

git@github.com:g33kzone/multi-repo.git
git@gitlab.com:g33kzone/multi-repo.git
Enter fullscreen mode Exit fullscreen mode

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)

git remote add origin git@github.com:g33kzone/multi-repo.git
Enter fullscreen mode Exit fullscreen mode

Configure Push Remote URLs

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

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
Enter fullscreen mode Exit fullscreen mode

This can be confirmed by running the following command

git remote show origin
Enter fullscreen mode Exit fullscreen mode

Push Multiple Repos

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

git push --set-upstream origin master
Enter fullscreen mode Exit fullscreen mode

Later only "git push" should also work.

Top comments (0)