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
remoA
tolocB
, then you are still wrong here. The correct approach should begit remote rm origin
and 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 calledorigin
and the other is calledoriginB
. Butgit
will useorigin
first. See next article for detailsOf 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 isgit pull origin
. If you are on themaster
branch, 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/config
file and take a look. Just entercat .git/config
on the command line. For example:This tells
git
two things:If you are currently on the
master
branch, then the defaultremote
isorigin
If you execute
git pull
in this case without any parameters, it is equivalent togit pull origin master
You can use
git push -u newOrigin newBranch
to change, thengit pull
is equivalent togit pull newOrigin newBranch
.Similarly, you can also
git config branch.master.remote newOrigin
and thengit config branch.master.merge refs/heads/newBranch
. The result is the same.