Skip to content

Instantly share code, notes, and snippets.

@Kovrinic
Last active February 20, 2024 04:38
Star You must be signed in to star a gist
Save Kovrinic/ea5e7123ab5c97d451804ea222ecd78a to your computer and use it in GitHub Desktop.
git global url insteadOf setup
# one or the other, NOT both
[url "https://github"]
insteadOf = git://github
# or
[url "git@github.com:"]
insteadOf = git://github

Replace git:// with https://

Rewrite any git:// urls to be https:// but, it won't touch sshurls (git@github.com:)

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

or replace with ssh

Use ssh instead of https://

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

sauce: https://gist.github.com/grawity/4392747 & @hansdg1

@tribela
Copy link

tribela commented Jan 17, 2022

@timmyyuan Pardon me, how to unset insteadOf in git global settings?

git config --global -e bring the editor for your git config. remove related setting on there

@timmyyuan
Copy link

Thanks @tribela , I have found another way to remove this setting:

git config --global --remove-section url."https://github.com/"

@IzhakJakov
Copy link

Is there a way to do something like that instead?

[url "https://github.com"]
  insteadOf = github.com/

# or

[url "git@github.com:"]
  insteadOf = github.com/

Basically without using the http:// or https:// prefix.

@tommy70404
Copy link

Thanks!

@frenchbeast
Copy link

Exactly what i was looking for thanks 👍

@tecnocat
Copy link

tecnocat commented Jan 9, 2023

It is possible to remove entries with credentials from command line scripts?

[url "https://user:token@repository.url.com"]
        insteadOf = https://repository.url.com

I tried git config --global --unset name <pattern> with no luck :(

@toddwalstad-eaton
Copy link

I am trying to do the same to remove old entries also with no luck. This pattern or [value_regex] as described in the document doesn't seem to work these url overrides.

@vuquang23
Copy link

thank !! 👍

@pklapperich
Copy link

Do you know how to set up with custom port? the default is 22

you have two options. In the below examples, the match is specific to an organization (ex you want to force ssh when working with your company's projects but https is fine for public projects). Just filter on and replace less if you want less.

Option 1: Entirely in gitconfig. The ssh:// is required to change ports.

# ~/.gitconfig
[url "ssh://git@github.com:1234/organization"]
  insteadOf = https://github.com/organization

Option 2: Use replacement in git config as well as replacement in ssh config.

# ~/.gitconfig
[url "git@github.com:/organization"]
  insteadOf = https://github.com/organization
```

```
# ~/.ssh/config
Host github.com github
    Hostname github.com
    User git
    Port 1234
```

Basically anything that you can set with `-o [optionName]` on the ssh commandline can be set via the config file. The line `Host` is space separated list of matching names that you type on the commandline (ex: `ssh github`) or use in URLs for things that use ssh under the hood (rsync, git, svn, etc). The `Hostname ...` option is the hostname that's used in-place-of what was matched.

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