Skip to content

Instantly share code, notes, and snippets.

@Kovrinic
Last active October 19, 2024 22:03
Show Gist options
  • Save Kovrinic/ea5e7123ab5c97d451804ea222ecd78a to your computer and use it in GitHub Desktop.
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 "[email protected]:"]
insteadOf = git://github
@jasong-au
Copy link

Any way to debug this? I'm trying to set something up for 'go install' to use a private repository and personal access token, but I can never tell if it is being called or not.

@pklapperich
Copy link

@jasong-au Any time git is called, it'll check the ~/.gitconfig file for matches based on insteadOf. This includes if go install is using git under the hood. Any time ssh is called, it'll check ~/.ssh/config for matching host definitions. This includes if git is using ssh under the hood.

So you can debug a ~/.ssh/config file using ssh, such as ssh github or ssh github.com and ensure it uses the hostname, username, and port defined in the config file.

You can debug a ~/.gitconfig using git.

Do something like this:

$ cat ~/.gitconfig
[url "https://gist.github.com/ea5e7123ab5c97d451804ea222ecd78a.git"]
   insteadOf = http://jasong-au

$ git clone http://jasong-au
Cloning into 'jasong-au'...
remote: Enumerating objects: 15, done.
remote: Total 15 (delta 0), reused 0 (delta 0), pack-reused 15 (from 1)
Receiving objects: 100% (15/15), done.
Resolving deltas: 100% (3/3), done.
(base)

Just make sure that whatever you put in your insteadOf = clause properly matches a URL for a git repo that go install is trying to access. And keep in mind that it's a find/replace matching from the start of the string, so you can swap any part of the start of the URL you want, including the entire URL. In my config I swap https://ourserver.organziation.example.com matching based on insteadOf = https://github.com/organization/ because we moved away from github and now have our own internal git server. By setting up the url mapping I didn't have to go through and update the URL for every repo already cloned on my workstation.

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