DEV Community

Xun Zhou
Xun Zhou

Posted on • Updated on

Push the same project to multiple different remote repositories at the same time by using git remote

Assume that you have the same project code project-awesome, but hosted on three different repositories:

## on Github
https://github.com/vikbert/project-awesome

## on GitLab
https://gitlab.com/vikbert/project-awesome

## on Bitbucket
https://bitbucket.com/vikbert/project-awesome
Enter fullscreen mode Exit fullscreen mode

And you use the GitHub repository as your MAJOR repository, but you wanna push also the new features to the other repositories on gitlab and bitbucket at the same time.

Here is the solution to make it possible:

1) define the major remote repository named origin

git remote add origin https://github.com/vikbert/project-awesome
Enter fullscreen mode Exit fullscreen mode

2) define another remote repository named all

git remote add all https://github.com/vikbert/project-awesome
Enter fullscreen mode Exit fullscreen mode

3) add the additional Urls to the remote group all

## we add the two other additional remote URL to the "all" remote.
git remote set-url all --push --add https://gitlab.com/vikbert/project-awesome
git remote set-url all --push --add https://bitbucket.com/vikbert/project-awesome
Enter fullscreen mode Exit fullscreen mode

4) check if the grouped URLs are set to the remote all

git remote -v
Enter fullscreen mode Exit fullscreen mode

we will see the remote "all" repository own the three different URLs

# origin https://github.com/vikbert/project-awesome (fetch)
# origin https://github.com/vikbert/project-awesome (push)
# all https://github.com/vikbert/project-awesome (fetch)
# all https://gitlab.com/vikbert/project-awesome (push)
# all https://bitbucket.com/vikbert/project-awesome (push)
Enter fullscreen mode Exit fullscreen mode

5) Now push the current changes to all of 3x remote repositories

## if your current local branch is "master"
git push -u all master
Enter fullscreen mode Exit fullscreen mode

💥 Remove the remote repository from the group all

git remote set-url all --push --delete https://bitbucket.com/vikbert/project-awesome
Enter fullscreen mode Exit fullscreen mode

Top comments (0)