Depending on who I work with, I get requests sometimes to push code not only to my working GitHub account but also to the client’s account. I’m using the Github client to update from my local machine to the Github repository, what do you do if you need to push code to another source code control system?
I will explain what I did to make this work for me, I like client tools for SaaS service, and I’m not that keen on using the command line to do all the administrative work for Git.
This is my Github client:
All I did was edit the .git/config in the source code folders that are under my Github control; what I did was add another line, URL =, as shown in this picture
All the other config values are set by the Github client on install, I just added one line. This works for me if you love the command line, you could do the following.
You can put the following in the
[remote "both"] url = url/to/first/remote url = url/to/other/remote
You can now push to both URLs using
git push both.
If you also want to fetch from them (useful for sync) you may add the following lines in your
[remotes] both = origin, other
Now you can also run
git fetch both
I would not recommend fetching from both, I would use one repro for backup purposes only so a push is enough to the backup repro.
Another way to do this is to follow commands on the command line.
$ git remote -v origin [email protected]:something.git (fetch) origin [email protected]:something.git (push) my_other_remote git://somewhere/something.git (fetch) my_other_remote git://somewhere/something.git (push)
You could do:
git remote set-url --add --push origin git://somewhere/something.git
git push origin
will push to both repositories. You might want to set up a new remote called both for this, however, to avoid confusion. For example:
git remote add both [email protected]:something.git git remote set-url --add --push both git://somewhere/something.git
git push both
… will try to push to both repositories.
# Push To Multiple Git Repositories
I use two git Repositories
- GitLab for internal Use and deployment
- GitHub for public open source code sharing
From the root folder of your project, add both repositories to the remotes:
git remote add origin <GitLab URL>
git remote add copy <GitHUb URL>
Run the git remote -v command to ensure that both remotes were successfully added
Now you are able to perform a push to the selected remote by specifying it in the git push command:
git push origin master
git push copy master
Create a new remote named “all”, and add GitLab and GitHub URLs to it
git remote add all <GitLab URL>```
git remote set-url all --add --push <GitLab URL>
git remote set-url all --add --push <GitHub URL>
git push all main
Have comments use the comment box below.