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?
If you don’t plan to associate
remoAtolocB, then you are still wrong here. The correct approach should begit remote rm originand thengit remote add origin (remoBUrl)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 tworemote, one of which is calledoriginand the other is calledoriginB. Butgitwill useoriginfirst. See next article for detailsOf course not. Unless you first update the local to one of the branches, and then go to
pullthe 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:This tells
gittwo things:If you are currently on the
masterbranch, then the defaultremoteisoriginIf you execute
git pullin this case without any parameters, it is equivalent togit pull origin masterYou can use
git push -u newOrigin newBranchto change, thengit pullis equivalent togit pull newOrigin newBranch.Similarly, you can also
git config branch.master.remote newOriginand thengit config branch.master.merge refs/heads/newBranch. The result is the same.