bluescion bluescion - 29 days ago 12
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 https://github.com/hackreactor/HRATX24-javascript-koans.git


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: https://github.com/hackreactor/HRATX24-javascript-koans.git. 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 https://github.com/hackreactor/HRATX24-javascript-koans.git (fetch)
origin https://github.com/hackreactor/HRATX24-javascript-koans.git (push)
upstream https://github.com/hackreactor/HRATX24-javascript-koans.git (fetch)
upstream https://github.com/hackreactor/HRATX24-javascript-koans.git (push)

$ git remote rm https://github.com/hackreactor/HRATX24-javascript-koans.git
fatal: No such remote: https://github.com/hackreactor/HRATX24-javascript-koans.git

$ git remote add origin https://github.com/BLuEScioN/HRATX24-javascript-koans.git
fatal: remote origin already exists.

Answer

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 https://github.com/BLuEScioN/HRATX24-javascript-koans.git
Comments