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:
[url "git://git.kde.org/"]
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):
[url "ssh://git@git.kde.org/"]
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://git@git.kde.org/” instead.
P.S. Before you ask: I’ve also added that tip to the git.kde.org manual on community.kde.org.
November 30, 2010 at 13:17
[…] konfigurasi lebih lanjut silakan baca disini dan disini. Tulisan ini hanyalah terjemahan dan penafsiran bebas dari tulisannya Stefan […]
November 30, 2010 at 13:19
Slightly offtopic, but if you use zsh, you can use alias -g to accomplish the same, for any command.
I have “alias -g phonebt=’00:57:E5:88:5F:1F'”, so then I can use “phonebt” in bluetooth related applications, and it’ll be replaced by my phone’s address.
November 30, 2010 at 20:56
But that works only when you specify the URL on the command line, not when its coming from the config (as in “git pull origin master”).
November 30, 2010 at 19:56
Fantastic dude 🙂 GIT has some rarher nice peculiarities 🙂
November 30, 2010 at 23:37
Nice tip. I’m using this now:
[url “git@git.kde.org:”]
insteadOf = kde:
git clone kde:akonadi
December 1, 2010 at 08:26
Very clever, thank you for the tip! May I ask, what is the benefit of pushing through ssh but not pulling through the same? Or was it just an example to demonstrate the flexibility?
December 1, 2010 at 18:26
1. The git:// protocol uses bandwidth more efficiently (unless you need the integrity provided by SSH).
2. If you have key-based login with a passphrase-protected key, you do not need to enter your passphrase. Sure, you could use ssh-agent, but I like that I need to enter my key only for potentially harmful write operations (okay, harmful only if you do a forced push).
December 8, 2010 at 10:06
Ah, those are some valid points actually! Obviously I didn’t think that far… Learning every day 🙂
December 14, 2010 at 00:05
[…] Stefan Majewsky (majewsky): Tip of the day: Don’t remember Git clone URLs […]