git remote add (remote) (repoUrl) is used for two unrelated libraries
伊谢尔伦
伊谢尔伦 2017-06-29 10:08:59
0
1
1078

I have never thought about this question, and I feel it is not easy to describe, so I have never asked.
For example, there is project A and project B, and they are completely unrelated.
Projects A and B have remote warehouses and local warehouses, represented by remoA, locA, remoB, and locB respectively.

Question:
Under normal circumstances, locA is definitely associated with remoA, and locB is associated with remoB, regardless of whether this association is through cloning or git remote add (remote) (repoUrl). Now assume that the local libraries locA and locB already exist, but locB is in a newly initialized state and is still an empty library. Because of an operation error,
git remote add origin (remoAUrl) was executed.

I discovered this error later and executed
git remote add originB (remoBUrl)

So are remoA/master and remoB/master mapped to locB/master at this time?
If you execute git pull, will the remote branch codes of remoA and remoB be merged on the local master branch?

伊谢尔伦
伊谢尔伦

小伙看你根骨奇佳,潜力无限,来学PHP伐。

reply all (1)
phpcn_u1582

Due to an operation error,git remote add origin (remoAUrl)was executed. Later I discovered this error and executed git remote add originB (remoBUrl)

If you don’t plan to associateremoAtolocB, then you are still wrong here. The correct approach should begit remote rm originand thengit remote add origin (remoBUrl)

So are both remoA/master and remoB/master mapped to locB/master at this time?

Of course not. First of all, I think it may be more appropriate to say that an "associated" relationship has been established, similar to the feeling ofgit checkout -b --track xxx. Secondly, you added tworemote, one of which is calledoriginand the other is calledoriginB. Butgitwill useoriginfirst. See next article for details

If you execute git pull, will the remote branch codes of remoA and remoB be merged on the local master branch?

Of course not. Unless you first update the local to one of the branches, and then go topullthe other branch.

git pulldoes not specify subsequent parameters, the default isgit pull origin. If you are on themasterbranch, the default isgit pull origin master.

Of course, it may change depending on your settings. What is mentioned above is only the default situation. For the actual situation, please open the.git/configfile and take a look. Just entercat .git/configon the command line. For example:

[branch "master"] remote = origin merge = refs/heads/master

This tellsgittwo things:

  1. If you are currently on themasterbranch, then the defaultremoteisorigin

  2. If you executegit pullin this case without any parameters, it is equivalent togit pull origin master

You can usegit push -u newOrigin newBranchto change, thengit pullis equivalent togit pull newOrigin newBranch.
Similarly, you can alsogit config branch.master.remote newOriginand thengit config branch.master.merge refs/heads/newBranch. The result is the same.

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!