2

Yesterday, I needed to change the remote URL of a repository as I had just set up Bitbucket to use SSH keys and wanted to switch from HTTPS to SSH.

I accidentally used master instead of origin when pointing to the repo's remote address, like so:

git remote add master git@bitbucket.org:myaccount/myrepo.git

when I should have used (and later did use):

git remote set-url origin git@bitbucket.org:myaccount/myrepo.git

I checked git config to see if I had accidentally "broken" something and discovered the following two lines in there that aren't part of my other repositories as far as I could see (otherwise, they basically all look the same):

remote.master.url=git@bitbucket.org:myaccount/myrepo.git
remote.master.fetch=+refs/heads/*:refs/remotes/master/*

Now I'm somewhat confused. Isn't origin usually a shortcut/alias for my remote repository and master the one for my local repository? (Or maybe the main branch of my local repo? I never really work with different branches, so I usually only have one.) Or does remote master stand for the main branch in my remote repository? I.e. have I told git I have a remote master branch to differentiate it from other branches (which don't actually exist!)?

Unfortunately, remote.master.url doesn't turn up many Google results. It's mentioned once in this Stackoverflow thread: What is "git remote add ..." and "git push origin master"?, but that thread doesn't give any explanation on how to remove it again either.

I tried to get rid of remote.master.url by doing this:

git remote set-url --delete master git@bitbucket.org:myaccount/myrepo.git

but that only resulted in a fatal: Will not delete all non-push URLs error message of which I have no idea what it means. (There's only one Google result for it, which is this other Stackoverflow thread, which doesn't deal with the error message itself: fatal: I don't handle protocol. Side note: too bad I don't have enough reputation to let user1888797 know he can retrieve the config file with git config --list.)

Is there some way to "reset" remote.master.url? Or can it not be changed once it's set? Should I just ignore it? Might it lead to more confusion later on?

Community
  • 1
  • 1
Kay
  • 797
  • 1
  • 6
  • 28

1 Answers1

3

You can try to rename it:

git remote rename master origin

Or does remote master stand for the main branch in my remote repository?

No, here 'master' is just the name of a remote, it is a key referring to a value (the remote url).

If remote origin still exists, then:

git remote remove master
git remote set-url origin git@bitbucket.org:myaccount/myrepo.git
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • That did the trick, thank you! (origin still existed, so I tried the other two commands and they worked.) Still don't understand all the theory behind it but the two remote.master lines in my config file are gone. (; – Kay Jul 28 '13 at 15:02
  • @Kay Great! It is just a string being used as a shortcut for a remote url. – VonC Jul 28 '13 at 15:21