Home > database >  Unable to set the Git https url – it switches automatically to git protocol
Unable to set the Git https url – it switches automatically to git protocol

Time:12-28

There is a very weird issue I have seen today on a Windows machine, specifically: git push origin master would fail with a message similar with this:

Unable to push to git://github.com/user/repo
Please use https://github.com/user/repo

Cool, so we tried git remote set-url origin 'https://github.com/user/repo'.

When we tried to push again, a new error appeared:

Unrecognized protocol 'https

This particular error, strangely, happens because of the way how Command Prompt looks at the wrapping quotes, so it may be not related to git.

Ran again, the same command, but without quotes: git remote set-url origin https://github.com/user/repo

Now, surprise! When running git remote -v it should the git://github.com/user/repo.

The exact behavior happens when using GitHub for Desktop. When setting an https url in this format: https://github.com/user/repo it is automatically changed to git://github.com/user/repo.


We fixed the issue by switching to ssh urls, but this still remains a mistery.


Why is this happening at all? How to debug this?

CodePudding user response:

Git has a feature where you can rewrite URLs by transforming one set of patterns into another. This is the url.*.insteadOf pattern.

You can run git config -l --show-origin | grep insteadof to see if there are any such entries in your config and what file they're in. If there are, you can remove them from the config file, which should make things work as expected.

  • Related