Git adds multiple URL addresses to the remote library

Source: Internet
Author: User

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 originis to add a row of records to the config file for the current Git project.
There are two ways to open config files :

    1. Using commandsgit config -e
    2. 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 masterwhen 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.