DEV Community

loading...

Push multiple remote repositories

vikbert profile image Xun Zhou Updated on ・1 min read

Assume that you have 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 remote repository, but you wanna push also the awesome features to the other repositories on gitlab and bitbucket at the same time.

Here is the solution to make it possible:

define the major remote repository named "origin"

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

define another remote repository named "all", that will be used as the remote group

## 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

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

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

Discussion (0)

pic
Editor guide