bluescion bluescion - 9 months ago 51
Git Question

Added incorrect Git remote; can't remove it or overwrite it with another remote

I incorrectly added the wrong remote origin for my git repo. I never explicitly set my repo's remote origin. I think it must have been set by default when, before setting up a remote origin, I ran:

$ git remote add upstream

I did this so that in case the code from the original (upstream) repo from which I forked changed, the changes would also be uploaded and reflected in my fork. I can't be sure that this command set my remote origin since I am still in the early stages of getting acquainted with git, but when ran

$ git remote -v

git told me that that my origin was: I've tried removing this remote and overwriting it, but neither work. When trying to remove it, I get the error message - fatal: No such remote, and when I try to overwrite it, I get the error messgae - fatal: remote origin already exists. These two error messages seem to be contradictory, so I am not sure how to proceed. Can anyone help me understand what is going on better and how I can get git to reset my remote to the proper url?

Here are the git commands I ran and the output that git gave for them:

$ git remote -v
origin (fetch)
origin (push)
upstream (fetch)
upstream (push)

$ git remote rm
fatal: No such remote:

$ git remote add origin
fatal: remote origin already exists.

Answer Source

git remote rm takes the name of the remote (in this case origin) as its command.

Alternatively you can also just update the URL of the remote like so:

git remote set-url origin