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.

Advertisements

9 Responses to “Tip of the day: Don’t remember Git clone URLs”


  1. […] konfigurasi lebih lanjut silakan baca disini dan disini. Tulisan ini hanyalah terjemahan dan penafsiran bebas dari tulisannya Stefan […]

  2. AP² Says:

    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.

    • Stefan Majewsky Says:

      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”).

  3. Ivan Says:

    Fantastic dude 🙂 GIT has some rarher nice peculiarities 🙂


  4. Nice tip. I’m using this now:

    [url “git@git.kde.org:”]
    insteadOf = kde:

    git clone kde:akonadi


  5. 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?

    • Stefan Majewsky Says:

      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).


  6. […] Stefan Majewsky (majewsky): Tip of the day: Don’t remember Git clone URLs […]


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s