Tip of the day: Don’t remember Git clone URLs
November 29, 2010
It can be fun to read into manpages, esp. if the manpages in question are as good as the ones available for Git. It turns out that Git has an interesting mechanism for automatic URL rewriting. For example, if you find the following command too long:
git clone git://git.kde.org/amarok
Then you can define a URL alias by putting the following into the file .gitconfig in your home directory:
insteadOf = kde://
Now the command shortens considerably:
git clone kde://amarok
You could also choose only “kde:” instead of “kde://”, but I like that the former looks like a normal URL. If you have a developer account, you might want to push commits via SSH. If so, you could change the “git://” URL into an SSH URL, or you can specify a separate URL alias for pushing. Add the following to the global gitconfig (in addition to the lines above):
pushInsteadOf = kde://
Now everything works automagically. You pull from “kde://” which gets rewritten to “git://git.kde.org/”, but when you want to push something, “kde://” will be rewritten to “ssh://email@example.com/” instead.
P.S. Before you ask: I’ve also added that tip to the git.kde.org manual on community.kde.org.