DengDeng
DengDeng

Reputation: 543

I added multiple git remote name on one url, what will happen if i push?

I just started to learn git. I have read how to add remote repository and connect it to local repository. But when I test it, I ran the command git remote add three times, and added there name on one url, like :

$ git add remote learnGit xxxxxx/learnGit.git
$ git add remote origin xxxxxx/learnGit.git
$ git add remote orign xxxxx/learnGit.git

$ git remote
learnGit
origin
orign

If I want to pull later, does it work out same on:

git pull learnGit master
git pull origin master
git pull orign master

Thanks.

Upvotes: 2

Views: 75

Answers (2)

Vishwanath
Vishwanath

Reputation: 6004

I am trying to go into more details, which might not be needed here.

git is distributed version control management system. Each remote you add becomes a separate repository altogether. For each remote git keeps its history in local pointer with the same name.

Eg. For master branch on learnGit remote. The local pointer will be leranGit/remote.

These local pointers are updated when you do fetch of these remotes. (pull is fetch and merge).

If you create multiple URL to same url. It doesnt make any difference if you are doing git pull to merge with local, since all three remotes will see the same changes which are on remote.

But there might be case that you may have different states in local pointers for these remotes.

Eg If let say some other developer has made some commit and push to master.

git fetch learnGit/master # local master/learnGit updated to latest master on remote

In above case result of following will be different after running above command.

git merge learnGit/master # Will merge with latest commits

git merge origin/master # Will merge with commits which are not on remote, Since local pointer of origin/master is not updated yet by means of fetch

Upvotes: 0

1615903
1615903

Reputation: 34733

Yes, all the pull commands will work the same since all the remotes point to the same repository. Same with push.

Upvotes: 2

Related Questions