https://torbjornzetterlund.com/wp-content/uploads/2015/06/git-logo-960x600_c.png

Git: Pushing your code to two different source code control system using Github client


Depending on who I work with, I get request sometime to push code not only to my working github account also the clients 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 to SaaS service, I’m not that keen on using the command line to do all the administrative work for Git.

This is my Github client

Pushing-git-to-two-repositories

All I did was to edit the .git/config in the source code folders that is under my Github control, what I did was adding another line url = as shown in this picture

git config

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

.git/config

file:

[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

.git/config

file:

[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 do the following 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

Then,

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

… then:

 git push both

… will try to push to both repositories.

Have comments use the comment box below.

Menu