brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: url.insteadOf makes git use ssh for https GitHub addresses

Git
~/tips/tip-git-url-insteadof-ssh

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

Rewrites https GitHub URLs to ssh automatically for clone, fetch and submodules.

Copied clone URLs are often https, but I would rather use my ssh key everywhere. Instead of editing every remote by hand, git can rewrite the address for me.

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

Any URL that starts with the insteadOf value is rewritten to start with the base instead, as the manual puts it. So git clone https://github.com/example/project.git now actually uses [email protected]:example/project.git. It also works for submodules and for dependency tools that call git behind the scenes, which is where it earns its place.

When more than one rule matches, the longest match wins. A related setting, pushInsteadOf, only rewrites the address used for pushing, so you can fetch over https and push over ssh. If a remote has its own pushurl, git ignores pushInsteadOf for it.

Check the result with git remote -v or git ls-remote https://github.com/example/project.git.

Caveat: it is invisible. A year later you may wonder why a https URL asks for an ssh key, and the answer sits in ~/.gitconfig. On a machine or in a CI job without that key, the rewritten address fails, so keep the rule in your personal config, not in a shared one.

Further reading: git config, url.<base>.insteadOf (Git documentation)

Going deeper: Moving on from hdtv: how to export your TV show list to Trakt.tv

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link