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?

4

1 回答 1

3

您可以尝试重命名它:

git remote rename master origin

还是 remote master 代表我的远程存储库中的主分支?

不,这里 ' master' 只是一个远程的名称,它是一个引用值的键(远程 url)。

如果远程origin仍然存在,则:

git remote remove master
git remote set-url origin git@bitbucket.org:myaccount/myrepo.git
于 2013-07-28T14:46:22.707 回答