Git adds multiple URL addresses to the remote library, Giturl
Catalogue [-]
- Premise
- Use process
- Principle Analysis
- Attention
- Other
- Reference articles
Author: shede333
Home: http://my.oschina.net/shede333 && http://blog.sina.com.cn/u/1509658847
Copyright Notice: Original article, copyright notice: Free Reprint-Non-commercial-non-derivative-maintain attribution | [Creative Commons by-nc-nd 3.0] []
Premise
In general, we add remote libraries to git, which are generally
git remote add origin
(You can use a real address instead of \ )
But you might want to push your local git repository to GitHub and push it to the git@osc of open source China, how to solve it.
Some people may use two or more remote libraries, that is, add a remote library git remote add origin2
;
This method is inefficient because you want git to push two times to complete the push to two libraries.
In fact, there is another way, a remote library of git can correspond to multiple addresses, that is, I can let the remote library origin has multiple URL addresses. Here's how:
Use process
First, we start from scratch, assuming that you now want to add 3 remote library addresses, respectively:
\ https://git.oschina.net/shede333/swioslibary.git
\ https://git.oschina.net/shede333/swscrollbar.git
\ https://github.com/shede333/CoreAnimationTestSW.git
First, add the first address firstgit remote add origin
Then add a second addressgit remote set-url --add origin
Add a third addressgit remote set-url --add origin
.... In turn
This completes the addition of more than one address to the Origin library, as long as the use of a single git push origin master
push to 3 in the library ( git push
can also be used)
Principle Analysis
git remote set-url --add origin
is to add a row of records to the config file for the current Git project.
There are two ways to open config files :
You add a line every time you execute git remote set-url --add origin
it, such as:
git remote -v
: Displays the details of all current remote libraries, displayed in the format远程库名字 url连接(类型)
Therefore, you can directly add the URL directly in the config to modify is also possible, do not have to execute the git command.
Attention
git push origin master
when used, you can push to multiple URL addresses of origin,
But git pull
when used, you can only pull a URL address in origin (i.e., fetch-url, for example), and this fetch-url defaults to the first address you added to Origin.
If you want to change, only need to change the config file, the order of the three URLs, Fetch-url will directly correspond to the first UTL connection.
Other
I recently saw this article also good, similar principle: The project is hosted simultaneously to GitHub and Git@osc
be interested to see
Reference articles
Idea/git setting up multiple push remote warehouses or simultaneously submitting multiple push warehouses
From: http://my.oschina.net/shede333/blog/299032
http://www.bkjia.com/PHPjc/1114476.html www.bkjia.com true http://www.bkjia.com/PHPjc/1114476.html techarticle git adds multiple URL addresses to the remote repository, Giturl directory [-] premise Use flow principle Analysis Note Other reference article author: shede333 home: http://my.oschina.net/shede333http:/...