Catalogue [-]
- Premise
- Use process
- Principle Analysis
- Attention
- Other
- Reference articles
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 <url>
(You can use the real address instead of \<url\>)
But you might want to push your local git repository to GitHub and push it to open source China's [email protected], how to fix 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:
\<url1\> https://git.oschina.net/shede333/swioslibary.git
\<url2\> https://git.oschina.net/shede333/swscrollbar.git
\<url3\> https://github.com/shede333/CoreAnimationTestSW.git
First, add the first address firstgit remote add origin <url1>
Then add a second addressgit remote set-url --add origin <url2>
Add a third addressgit remote set-url --add origin <url3>
.... 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 :
- Using commands
git config -e
- In the root directory of the current Git project, the file is located in a. Git/config (. Git directory as a hidden file)
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 also hosted on GitHub and [email protected]
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
Git adds multiple URL addresses to the remote library