8

I've observed that my Git repository has two remotes for origin because when I run this:

git config --get-regexp 'remote\\.origin\\..*'

I get two results:

remote.origin.url https://user:password@my-repo:7990
remote.origin.url http://my-repo.com:7990/scm/my-project.git

However, I fail to delete either of them. For instance, if I try to delete the first one, like this:

git remote set-url --delete origin https://user:password@my-repo:7990

I get:

fatal: could not unset 'remote.origin.url'

Any idea why this error appears?

bsky
  • 19,326
  • 49
  • 155
  • 270
  • 1
    Maybe this is set in different config files and git is failing to edit one of them. You could manually edit those files and remove one of the entries. – Samir Aguiar Mar 23 '17 at 16:11
  • 1
    The only config file that I know of is in `.git/config` and that only contains one address. Any idea where there could be another config file? – bsky Mar 23 '17 at 16:34
  • Yeah, there are four places for configurations. Check [this answer](http://stackoverflow.com/a/17756808/2883579). – Samir Aguiar Mar 23 '17 at 16:38
  • 2
    And you can also run `git config --list --show-origin` to see from which file the values come from. – Samir Aguiar Mar 23 '17 at 16:39
  • Thanks. That actually did it. I realised I had some redundant configuration in my home folder that was mixing things up. – bsky Mar 23 '17 at 17:12

3 Answers3

9

You can remove the remote origin then add again.

$ git remote rm origin                   # remove a first remote
$ git remote -v

# if you see your second origin
$ git remote rm origin                   # remove the second origin

$ git remote add origin <repo-url>       # add new origin

$ git remote -v                          # see all the remotes you have  
Sajib Khan
  • 22,878
  • 9
  • 63
  • 73
  • Firstly, this doesn't work. You need to use `add` instead of `set-url`. Secondly, even if try with `add`, I get `fatal: remote origin already exists` because the origin has two URLs pointing to it and only the first one is deleted with `rm`. – bsky Mar 23 '17 at 16:32
  • @octavian, yes `set-url` should be `add`. Try removing `origin` for two times. See if it works! – Sajib Khan Mar 23 '17 at 16:38
3

If it is a remote added with --push option you have to use --push option again to delete the remote like this:

git remote set-url --delete --push <remote_name> <remote_url_to_delete>

This will only delete the URL, not the remote.


I was having the same issue with a pushable remote added with --add --push option like this:

git remote set-url --add --push <remote_name> <remote_url>

This is usually made to have diferent URLs to the same remote to push changes faster to diferent places.

If you would like to do that, after adding the URLs you just have to use:

git push <remote> <branch>

And it will push to every URL added to your remote

0

git unset-all remote.origin.push

Zartog
  • 1,906
  • 1
  • 16
  • 27