Feb 12 2009

Initialize a remote git repository

So you create a git repository (repo) on your local machine (foo) and begin hacking away. Then, you want to push a backup copy of that repo to another box (bar). What’s the best way to do that? There are many ways to do it, but some ways are dangerous and some are just cumbersome.

Ideally, git would have an option to push that instructs it to initialize the remote repository and just do the right thing. I hope this is in our future, but for now we have to do some dancing around.

The canonical way is
bar:~/repo$ git clone --mirror local:repo
...
foo:~/repo$ git push bar:repo --mirror

but that’s not always feasible due to firewalls and nasty NATs.

Unwise methods include copying the working tree with rsync or scp, doing something like the above without --bare or --mirror (which implies --bare), and other methods that would have you pushing to a non-bare repository.

The best method I’ve found is this:
bar:~$ git --git-dir=repo init --bare
foo:~/repo$ git remote add --mirror bar bar:repo
foo:~/repo$ git push bar
...

We set up a bare repository on bar, then set up a “remote” for bar which automatically mirrors (you could do that with the canonical method described above too), so it sends the whole shebang. After that, we push as we normally would.


Nov 30 2007

The Nerd Handbook

Like spr, I got a good laugh, and creepy feeling, reading about myself on a stranger’s blog. It’s nice to know there are people out there just like you, but it can be disconcerting at the same time. My wife thought I was laughing at the episode of The Cosby Show she was watching, which I sometimes was. I had her fooled.

I enthusiastically referred my wife to read it, but she seemed to be only mildly amused. I guess she found the truth less funny and more sobering, and who can blame her? To all of you out there who have fallen for a geek, my condolences and congratulations. I think we’re a pretty good lot, and you couldn’t do better, but it can be a strange thing to be married to a geek. To my geek friends, don’t forget to at least try to make it easier on her, and worth her while.

A friend recently asked me to share some six things about myself. Normally I would just send her an email with six things and not propogate the forward, but the stranger already wrote it all down! The only thing I have to add is that I watch an episode of some classic Sci-Fi show nearly every day, usually during a meal. Usually Star Trek or Doctor Who. Erin likes Star Trek well enough and humors me. Jonny likes Doctor Who better, so when Erin’s out (or not paying attention) we cozy up on the couch for some foam monsters. There’s just something about that theme music and the Tardis sound effects that makes even the tackiest foam monster worth watching.

I’m happy to announce that my wife is still my number one project. Other projects will come and go. Some will seem more important to her and even to me, at times. Mistakes like those aside, I plan to keep her number one, forever.