Sometimes we need to push a project to different remote repositories at the same time. Some people may think that each change is pushed to a different remote repository, but this method is very repetitive and inefficient, and very painful. How to push a project to different remote repositories at the same time is described below.


You probably know that git.osChina has such a feature.

As shown in figure:

Oschina is a remote repository for github and gits. osChina. This is a remote repository for both github and gits. osChina. Otherwise management will be very troublesome.

Push to multiple remote repositories simultaneously

  • Will need to firstpushThe code ofcloneTo local, IclonegithubWarehouse Address:
[email protected]:Jonzzs/SimpleNote.git
Copy the code
  • I need to combine this code withpushgithubgit.oschinaWarehouse, below is the address:
[email protected]:Jonzzs/SimpleNote.git
  
[email protected]:Jonzzs/SimpleNote.git 
Copy the code
  • Open the local project under the text editor.gitIn folderconfigFile:

  • This folder is hidden by default in your project. You can use Finder to open the config file after displaying the hidden file, or use terminal commands to modify the config file. I won’t describe how to do this here.

  • Here I use the Source Tree tool directly to modify the config file, open the project and select Settings – remote Repository – Edit config file… You can open the config file directly.

  • The editorconfigFile, modify[remote "origin"]The following:
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"] / / modify the url = [email protected]: Jonzzs/SimpleNote git fetch = + refs/heads / * : refs/remotes/origin / * [branch"master"]
	remote = origin
	merge = refs/heads/master
Copy the code

As shown in figure:

  • in[remote "origin"]Finally, addpushurlAt the same time topushTo multiple remote warehouses:
[core]
	repositoryformatversion = 0
	filemode = true
	bare = false
	logallrefupdates = true
	ignorecase = true
	precomposeunicode = true
[remote "origin"] / / pushurl to push at the same time is added to the url = [email protected]: multiple remote warehouse Jonzzs/SimpleNote git fetch = +refs/heads/*:refs/remotes/origin/* pushurl = [email protected]:Jonzzs/SimpleNote.git pushurl = [email protected]:Jonzzs/SimpleNote.git [branch"master"]
	remote = origin
	merge = refs/heads/master
Copy the code

As shown in figure:

  • After the editorcommand + sSave it, you’re done, and then you use itgit pushWill at the same timepushGo to these two remote warehouses and test them out.

Note: The default url is the address you clone from, but the default address of the pushurl is the address you pulled from when you did git pull. Pushurl can be filled in more than one, you want to push several remote warehouses at the same time to fill in several. In addition, the name of the remote repository can be different, but for the Branch Branch, the two repositories must be the same.


The method is such, there may be other methods on the net, want to know by oneself to search, this method is simpler.

In the future, you will be grateful for your hard work now, and wish you and your readers a better way of development.

My portal: blog, Book, Twitter, GitHub.