dark theme

Pull from faster read-only repos with git's pushInsteadOf

I pull changes from my own repos on different places: my laptop, my home computer, my work computer, my router…

On every place, when fetching changes I have to enter my passphrase. That does not make much sense since most of the repositories can be fetched anonymously.

The issue can be analyzed from a different point of view. When do I need to authenticate myself? → Only on push.

One solution for that is pushInsteadOf. Since git v1.6.4, this option exists to specify what URL git should use when pushing changes. Now I need to change the URLs in all my repos to use by default the read-only URL: for example changing git@github.com:billiob/bfb.git to https://github.com/billiob/bfb.git. I use https since it should have a smaller impact on the servers than the git protocol.

Then I've added the following to my ~/.gitconfig:

1
2
3
[url "git@github.com:billiob/"]
    pushInsteadOf = https://github.com/billiob/
    pushInsteadOf = git://github.com/billiob/

Those 3 lines work for all my github repos. An URL like https://github.com/billiob/bfb.git will be rewritten to git@github.com:billiob/bfb.git.

No need to enter my passphrase when fetching changes!

Edit: You can also add an url for push using git remote.

blog comments powered by Disqus

If you enjoyed this article, feel free to Flattr this.