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

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 associate remoA to locB, then you are still wrong here. The correct approach should be git remote rm origin and then git 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 of git checkout -b --track xxx. Secondly, you added two remote, one of which is called origin and the other is called originB. But git will use origin first. 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 to pull the other branch.

git pull does not specify subsequent parameters, the default is git pull origin. If you are on the master branch, the default is git 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/config file and take a look. Just enter cat .git/config on the command line. For example:

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

This tells git two things:

  1. If you are currently on the master branch, then the default remote is origin

  2. If you execute git pull in this case without any parameters, it is equivalent to git pull origin master

You can use git push -u newOrigin newBranch to change, then git pull is equivalent to git pull newOrigin newBranch.
Similarly, you can also git config branch.master.remote newOrigin and then git 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