Preethi Vaidyanathan
Preethi Vaidyanathan

Reputation: 1322

Why does git remote -v not show the same url as my .git/config?

I am trying to switch my remote from HTTPS to SSH. First I verify that it started out as HTTPS. I run:

$ git remote get-url origin

result: https://<repo>.git

I then run $ git remote set-url origin [email protected]:<repo>.git

Then I run so set the remote URL that I want: $ git remote get-url origin

and it STILL returns https://<repo>.git!

...however, if I run:

git config --get remote.origin.url

Then I get back the expected url of [email protected]:<repo>.git

Upvotes: 3

Views: 1375

Answers (2)

spaceghost
spaceghost

Reputation: 486

Check git global config

Check the global git config for any insteadOf settings which automatically replace git urls with https urls.

git config -l

...
url.https://github.com/[email protected]:
url.https://.insteadof=git://
...

Unset those:

git config --global --unset-all url.https://github.com/.insteadof
git config --global --unset-all url.https://.insteadof

Alternatively you could use git config --global --edit to edit the global config in your editor (nano, vim etc) and delete the relevant sections.

Test again and hopefully it will show the same urls with both git remote -v and git config --get remote.origin.url.

I had the same problem in a VM environment which I received from a colleague, and since I hadn't realised they had added these global config settings I couldn't figure out what was going on. It seems that some people use this as a workaround in environments which block access to git urls for whatever reason.

Confirm ssh authentication is working

Aside from checking git's config settings, it can be helpful to make sure that ssh authentication to git is working properly.

ssh -Tv [email protected]

If it succeeds you should see a message like the following. Any sort of error suggests there's a problem with your ssh keys, ssh settings, or environment related to ssh and you should check that first.

Hi userName! You've successfully authenticated, but GitHub does not provide shell access.

Upvotes: 2

Try removing and then adding the origin again, if that is ok for you.

To remove origin,

$ git remote rm origin

Verify if the origin actully removed. The secondnd command should have given you a error.

$ git remote -v
$ git pull

Now add origin and verify,

$ git remote add origin [email protected]:username/repository-name.git
$ git remote -v

Upvotes: 0

Related Questions