4

I'm getting pretty comfortable with git but I've hit something that puzzles me. We use a local mirror, here, because we have a slow line. In order to point at the mirror, I have the usual stuff in .gitconfig.

The problem comes when I want to push. It appears that either I need an alias URL for the repo—not the one remapped in .gitconfig—or I need to edit .gitconfig to push to the real repo (not the mirror).

This really has to be a use pattern. How can I make the mirror seamless on pull and get it out of the way on push?

G. Blake Meike
  • 6,615
  • 3
  • 24
  • 40
  • @Cupcake has changed the meaning of this question that it is answered by hobbs' response. Useful, perhaps, but certainly not what I asked. – G. Blake Meike Jun 21 '14 at 14:16

2 Answers2

4

Set up a remote like

[remote "myrepo"]
url = mirror url here
pushurl = push url here

and then just set the remotes on your branches to be that remote.

hobbs
  • 223,387
  • 19
  • 210
  • 288
  • 1
    You can set this on the command line by running `git config remote.myrepo.url ...` and `git config remote.myrepo.pushurl ...`. – larsks Sep 14 '11 at 17:54
  • wooo... that's excellent larsks! Where's the doc for that? I guess I have to do it, separately, for each repo I use? "insteadOf" is nice cause it matches URL handles... – G. Blake Meike Sep 14 '11 at 19:14
  • It's in `git help config`. And yeah, I don't think you have any choice but to do it per-remote. – hobbs Sep 15 '11 at 00:16
  • 1
    Hey, just to be clear, this is not yet an answer. If, e.g., I am using the repo tool, I need some way of saying "*ALL* requests for X should go to my mirror instead of to X". I think it might be possible to use repo forall -c "..." and larsks' trick as a workaround, but what I'd really like is "roles" in .gitconfig, or a global --conf option to git, specifying an alternate config file. Or even, I suppose a pushUrl/insteadOf pair in .gitconfig – G. Blake Meike Sep 15 '11 at 19:19
  • Yep. Just checking to see that I hadn't missed anything, first. Lemme see if I can just implement it... – G. Blake Meike Sep 15 '11 at 23:05
0

I have a great workaround for this! Tip of the hat to Matthew McCullough.

It turns out that the GIT_CONFIG env variable has no affect, regardless of what the documentation says. On the other hand, the HOME env variable is the name of the directory in which git looks for .gitconfig. If you define HOME in the git command line, like so:

HOME=~/somewhere git ...

... git will obtain its configuration from the .gitconfig is found in the directory "~/somewhere. If that gitconfig does not rewrite URLs to point git at a mirror, you are talking to the origin. You can probably do it in an alias...

G. Blake Meike
  • 6,615
  • 3
  • 24
  • 40