I'm sure many of you go to places like the GitHub or GitLab UI to copy the URL to clone a repository. I thought I'd share a small configuration I found recently in my .gitconfig that helps save some time when setting remotes in Git repositories (or cloning new ones). Before I found this setting, I consistently found myself in a browser to copy/paste the clone URL (I'm sure I'm not alone). This eventually got a little tiring, so I spent some time looking for something that worked for me.

Turns out there's something for this! The feature that makes this possible is the insteadOf flag inside the .gitconfig file. This flag can act as a string replacement to allow "aliasing" of common URLs, and is documented here. It's pretty simple to configure. Below is a snippet from my configuration for popular Git hosts:

[url "git@github.com"]
	insteadOf = :
[url "git@github.com"]
	insteadOf = github
[url "git@gitlab.com"]
	insteadOf = gitlab
[url "https://bitbucket.org"]
	insteadOf = bitbucket

This allows me to skip the main URL boilerplate, and refer to remotes like in the commands below. As far as I know, this works for any place referencing a remote, so you can adopt it in any commands where it might be useful.

git clone github:whitfin/cachex
git remote add origin github:whitfin/cachex

It seems like a very small thing but it's a nice timesaver and helps keep you switching context between your terminal and your browser, as it's easier to do from memory. As I typically use GitHub more often than other Git hosts, I also have a : alias, to allow for this syntax:

git clone ::whitfin/cachex

This makes it much more productive in my day-to-day, since I tend to hop around repositories quite a lot. It's a little redundant to type out the full URLs every time, so this was definitely an improvement in my workflow. It's not a major thing, just thought I'd share!