让git / go获得使用代理域

Before you read: I don't want to do malicious things, but setup a tool chain to overcome the flaws of go get.

I want to have a setup that allows the following:

  • I have a set of domains, like github.com, bitbucket.org, etc.
  • If git clones/pushes/pulls with a remote repository from any of the domains the domains are resolved to an IP address of my proxy
  • For any other program the domains resolve to real IP addresses
  • My proxy should be a program that hosts/caches repositories and clones them from the real target if they are not in the cache. This program should be written in Go

The git commands must be used as normal. Git configuration may be changed.

The idea is to have all development computers of a team configured this way, so that any external repository is in fact a clone on the proxy. That clone could be managed in a centralized way (special changes, merges will upstream etc.) without affecting the import paths.

How would I setup the DNS faking? How must the proxy be built in order to properly work with git?

Starting with git 1.8.5, you can setup directly in git global settings proxy for specific urls:

[http "http://github.com" ]
  proxy = http://my.proxy:8080
[https "https://github.com" ]
  proxy = http://my.proxy:8080

See "Only use a proxy for certain git urls/domains?"

That helps when you want to use a proxy only for certain urls.