Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Force git to use https:// instead of git://
# npm using https for git
git config --global url."https://github.com/".insteadOf git@github.com:
git config --global url."https://".insteadOf git://
# npm using git for https
git config --global url."git@github.com:".insteadOf https://github.com/
git config --global url."git://".insteadOf https://
@robotfactory

This comment has been minimized.

Copy link

@robotfactory robotfactory commented Jul 18, 2017

Thank you for this. Great for getting around a poorly configured corporate web filtering system.

@doucetj

This comment has been minimized.

Copy link

@doucetj doucetj commented Dec 12, 2017

Also exactly what I needed, Thank you

@koutsenko

This comment has been minimized.

Copy link

@koutsenko koutsenko commented Feb 13, 2018

how to revert that ? :)

@alvaropinot

This comment has been minimized.

Copy link

@alvaropinot alvaropinot commented Feb 25, 2018

@koutsenko You can edit the whole global config file by running git config --global --edit and delete the line manually, should be at the bottom :)

@wizofe

This comment has been minimized.

Copy link

@wizofe wizofe commented May 9, 2018

Oh my days, saved my life. Thanks!

@duck2

This comment has been minimized.

Copy link

@duck2 duck2 commented Aug 15, 2018

thxthx

@g10guang

This comment has been minimized.

Copy link

@g10guang g10guang commented Oct 24, 2018

What about "ssh://" prefix?

Like ssh://user@git.example.com:8080/user/project

@rahulbhooteshwar

This comment has been minimized.

Copy link

@rahulbhooteshwar rahulbhooteshwar commented Jan 14, 2019

Thanks @taoyuan a lot. It worked like a charm.

@davidhsv

This comment has been minimized.

Copy link

@davidhsv davidhsv commented Feb 13, 2019

Man, I love you, marry me!

@amitsomani2000

This comment has been minimized.

Copy link

@amitsomani2000 amitsomani2000 commented Mar 16, 2019

Thanks a lot @taoyuan. It was a saviour.

@canoaf98

This comment has been minimized.

Copy link

@canoaf98 canoaf98 commented Apr 2, 2019

👍 If you know some place to find SSH Authentication problem solution, please let my know.

@pmckeegan

This comment has been minimized.

Copy link

@pmckeegan pmckeegan commented Apr 5, 2019

works, thanks!

@polishcode

This comment has been minimized.

Copy link

@polishcode polishcode commented Apr 25, 2019

Thank you @taoyuan.

@joseboretto

This comment has been minimized.

Copy link

@joseboretto joseboretto commented May 15, 2019

how to revert that ? :)

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

Check it with:
git config -l

@leemeans

This comment has been minimized.

Copy link

@leemeans leemeans commented May 16, 2019

Thanks, works perfect. @taoyuan

@Phexcom

This comment has been minimized.

Copy link

@Phexcom Phexcom commented Jun 14, 2019

how to revert that ? :)

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

Check it with:
git config -l

@joseboretto
Wow you just saved my life. 2 hours of headache try to change remote from https to ssh

@erkanzileli

This comment has been minimized.

Copy link

@erkanzileli erkanzileli commented Aug 9, 2019

You are saved my day. Thank you!

@Sarra-yocto

This comment has been minimized.

Copy link

@Sarra-yocto Sarra-yocto commented Aug 15, 2019

hey
can anyone help me ?
it didn't work out with git://git.yoctoproject.org/poky/, when this link is forced to turn to http://git.yoctoproject.org/poky/ i get this error :

fatal: repository 'https://git.yoctoproject.org/poky/' not found

am stuck there can anyone help me please ? :(

@quangtd92

This comment has been minimized.

Copy link

@quangtd92 quangtd92 commented Aug 30, 2019

THANKS YOU!!

@t3chn0m4g3

This comment has been minimized.

Copy link

@t3chn0m4g3 t3chn0m4g3 commented Oct 22, 2019

Thank you!

@furqon

This comment has been minimized.

Copy link

@furqon furqon commented Nov 4, 2019

wow, thank you!

@kunal15595

This comment has been minimized.

Copy link

@kunal15595 kunal15595 commented Dec 9, 2019

thanks

@quangtd92

This comment has been minimized.

Copy link

@quangtd92 quangtd92 commented Mar 19, 2020

thanks

@RafikFarhad

This comment has been minimized.

Copy link

@RafikFarhad RafikFarhad commented Apr 26, 2020

If any anyone need the reverse of this:

git config --global url."git@github.com:".insteadOf https://github.com/

git config --global url."git://".insteadOf https://
@big-omega

This comment has been minimized.

Copy link

@big-omega big-omega commented Apr 28, 2020

If any anyone need the reverse of this:

git config --global url."git@github.com:".insteadOf https://github.com/

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

thanks!

@alexey-sh

This comment has been minimized.

Copy link

@alexey-sh alexey-sh commented Jun 1, 2020

the following works for me for a corporate git

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

works only in global git config

@sueLan

This comment has been minimized.

Copy link

@sueLan 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://git@github.com/"]
	pushInsteadOf = https://github.com/
[url "ssh://git@gitlab.com/"]
	pushInsteadOf = https://gitlab.com/
@Janvierjavi

This comment has been minimized.

Copy link

@Janvierjavi Janvierjavi commented Jun 6, 2020

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

@shreyash-jain

This comment has been minimized.

Copy link

@shreyash-jain shreyash-jain commented Aug 21, 2020

thanks dear

@danistar47

This comment has been minimized.

Copy link

@danistar47 danistar47 commented Aug 28, 2020

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://git@github.com/morrisjs/morris.js.git

@jmac105

This comment has been minimized.

Copy link

@jmac105 jmac105 commented Oct 23, 2020

👍 really useful thanks

@iclal87

This comment has been minimized.

Copy link

@iclal87 iclal87 commented Oct 31, 2020

Successfully created project 'HalloweenProject2' on GitHub, but initial push failed: git@github.com: 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

This comment has been minimized.

Copy link
Owner Author

@taoyuan taoyuan commented Nov 1, 2020

Successfully created project 'HalloweenProject2' on GitHub, but initial push failed: git@github.com: 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

This comment has been minimized.

Copy link

@Roadrunner67 Roadrunner67 commented Nov 7, 2020

Can this also work with Git on Azure, where https is:
https://{organisation}.visualstudio.com/{project}/_git/{repository}
..and ssh is:
git@vs-ssh.visualstudio.com:v3/{organisation}/{project}/{repository}
...notice the /_git/ part of the https url.

@flymg

This comment has been minimized.

Copy link

@flymg flymg commented Nov 23, 2020

works only in global git config

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

@aggresss

This comment has been minimized.

Copy link

@aggresss 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

This comment has been minimized.

Copy link

@bhela 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:
git@vs-ssh.visualstudio.com: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

This comment has been minimized.

Copy link

@YaidelLuis YaidelLuis commented Apr 28, 2021

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

This comment has been minimized.

Copy link

@magic990619 magic990619 commented Apr 30, 2021

It's working! Many Thanks

@younasm

This comment has been minimized.

Copy link

@younasm 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

This comment has been minimized.

Copy link

@BodhiHu BodhiHu commented Jul 30, 2021

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

git config --global url."git@github.com:".insteadOf "https://github.com/"
@younasm

This comment has been minimized.

Copy link

@younasm younasm commented Aug 4, 2021

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

git config --global url."git@github.com:".insteadOf "https://github.com/"

did not work for me.

@adam-nielsen

This comment has been minimized.

Copy link

@adam-nielsen adam-nielsen commented Sep 14, 2021

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

git config --global url."https://github.com/".insteadOf ssh://git@github.com

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.

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