Skip to content

Instantly share code, notes, and snippets.

@taoyuan
Last active November 12, 2024 14:24
Show Gist options
  • Save taoyuan/bfa3ff87e4b5611b5cbe to your computer and use it in GitHub Desktop.
Save taoyuan/bfa3ff87e4b5611b5cbe to your computer and use it in GitHub Desktop.
Force git to use https:// instead of git://
# npm using https for git
git config --global url."https://github.com/".insteadOf [email protected]:
git config --global url."https://".insteadOf git://
# npm using git for https
git config --global url."[email protected]:".insteadOf https://github.com/
git config --global url."git://".insteadOf https://
@big-omega
Copy link

If any anyone need the reverse of this:

git config --global url."[email protected]:".insteadOf https://github.com/

git config --global url."git://".insteadOf https://

thanks!

@alexey-sh
Copy link

alexey-sh commented Jun 1, 2020

the following works for me for a corporate git

[url "https://git.scm.corporate.com/"]
	insteadOf = ssh://[email protected]/

works only in global git config

@sueLan
Copy link

sueLan commented Jun 2, 2020

https://www.jvt.me/posts/2019/03/20/git-rewrite-url-https-ssh/
If you only want to push over SSH, but not pull over HTTPS.

[url "ssh://[email protected]/"]
	pushInsteadOf = https://github.com/
[url "ssh://[email protected]/"]
	pushInsteadOf = https://gitlab.com/

@Janvierjavi
Copy link

thank you for your great support, I love this game.....

@shreyash-jain
Copy link

thanks dear

@danistar47
Copy link

getting error when running npm install
npm ERR! code ENOENT
npm ERR! syscall spawn git
npm ERR! path git
npm ERR! enoent Error while executing:
npm ERR! enoent C:\Program Files\Git\cmd\git.EXE ls-remote -h -t ssh://[email protected]/morrisjs/morris.js.git

@jmac105
Copy link

jmac105 commented Oct 23, 2020

👍 really useful thanks

@iclal87
Copy link

iclal87 commented Oct 31, 2020

Successfully created project 'HalloweenProject2' on GitHub, but initial push failed: [email protected]: Permission denied (publickey). Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

could you help me with this

@taoyuan
Copy link
Author

taoyuan commented Nov 1, 2020

Successfully created project 'HalloweenProject2' on GitHub, but initial push failed: [email protected]: Permission denied (publickey). Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

could you help me with this

You should generate a local ssh key and add the public key to github SSH keys, and it should be work.

@Roadrunner67
Copy link

Can this also work with Git on Azure, where https is:
https://{organisation}.visualstudio.com/{project}/_git/{repository}
..and ssh is:
[email protected]:v3/{organisation}/{project}/{repository}
...notice the /_git/ part of the https url.

@flymg
Copy link

flymg commented Nov 23, 2020

works only in global git config

--global seems to be a necessary fact.. :(

@aggresss
Copy link

aggresss commented Dec 6, 2020

https://github.com/aggresss/dotfiles/blob/c7e5bb6e7d71cf5e5d334504148a21b5eeb6e6fa/home/.bash_aliases#L621

# git config insteadOf
# $1: https/ssh/unset; null to display
# $2: domain name
function git_insteadof()
{
    local url="github.com"
    if [ $# -ge 2 ]; then
        url=$2
    fi
    case $1 in
        ssh)
            git config --global --unset-all url."https://${url}/".insteadof
            git config --global url."git@${url}:".insteadOf "https://${url}/"
            ;;
        https)
            git config --global --unset-all url."git@${url}:".insteadof
            git config --global url."https://${url}/".insteadOf "git@${url}:"
            ;;
        unset)
            git config --global --unset-all url."https://${url}/".insteadof
            git config --global --unset-all url."git@${url}:".insteadof
            ;;
        *)
            echo; git config -l | grep -E "url\.|\.insteadof=" && echo
            ;;
        esac
}

@bhela
Copy link

bhela commented Jan 11, 2021

Can this also work with Git on Azure, where https is:
https://{organisation}.visualstudio.com/{project}/_git/{repository}
..and ssh is:
[email protected]:v3/{organisation}/{project}/{repository}
...notice the /_git/ part of the https url.

Hello dear, can you please help me with the same issue on organization.visualstudio? Thank you

@YaidelLuis
Copy link

Alguien podría ayudar con el comando para permitir a git usar http y https al momento de clonar
Estoy detrás de un proxy y me da error la clonación

@magic990619
Copy link

It's working! Many Thanks

@younasm
Copy link

younasm commented May 22, 2021

Please someone help me I tried so many things but it's not working. I'm trying to npm install to install the dependencies for the Github repository it installs some dependencies but at the end, it shows this ERROR.

npm ERR! Error while executing:
npm ERR! C:\Program Files\Git\cmd\git.EXE ls-remote -h -t https://github.com/debris/bignumber.js.git
npm ERR!
npm ERR! Host key verification failed.
npm ERR! fatal: Could not read from remote repository.
npm ERR!
npm ERR! Please make sure you have the correct access rights
npm ERR! and the repository exists.
npm ERR!
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Younas\AppData\Roaming\npm-cache_logs\2021-05-22T06_40_23_639Z-debug.log

@BodhiHu
Copy link

BodhiHu commented Jul 30, 2021

the inverse, forcing git to use ssh instead of https:

git config --global url."[email protected]:".insteadOf "https://github.com/"

@younasm
Copy link

younasm commented Aug 4, 2021

the inverse, forcing git to use ssh instead of https:

git config --global url."[email protected]:".insteadOf "https://github.com/"

did not work for me.

@adam-nielsen
Copy link

I needed to add another one to get it working with Node's NPM

git config --global url."https://github.com/".insteadOf ssh://[email protected]

This adds an ssh:// prefix and removes the : suffix. It allows downloading public packages from GitHub repositories in environments like Docker where there are no SSH keys.

@Connor-Flewitt
Copy link

If anyone found themselves unable to revert the config using the suggested commands, go into the git config editor and manually delete what you want to remove :)

git config --global -e

For anyone unfamiliar with the editor, press "i" to start editing, "esc" to stop editing, and " : -> w -> q " to save and quit the editor.

@robiparvez
Copy link

@joseboretto
Bro, you saved me headache. Thanks.

@sd445419855
Copy link

Thank you!! You just saved my life.

@E-wallace0001
Copy link

All the yes. Thank you !

@tamipangadil
Copy link

This worked like a charm 🥇

@iamnothere101
Copy link

When using ssh (git config --global url."[email protected]:".insteadOf https://github.com), is there a way to authenticate (using A PAT)? I know it's possible with https, don't see a way to provide a PAT (via Github secret) when using SSH method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment