Gitolite with friends on server and such
Posted: January 25th, 2011 | Author: Deke | Filed under: The IT Life | Tags: ITI’m mainly a lone-wolf developer but sometimes (and more and more so) I need to work with other people outside of my dungeon. I have one el-cheapo box acting as the ssh, web, git, and backup server. I think this is a fairly typical setup. I wanted to take an existing project, add it to git, and share it with other dudes while still being able to code directly (when necessary) on the server itself. The solution turned out not to be so obvious. Well, not to me at least.
Here’s how I set up git on that box; thanks to Ubuntu, Gitolite and specifically Silas Sewell’s quick guide.
First, the standard installation stuff you’ll find on every blog:
1/ [server] apt-get install gitolite 2/ [client] ssh-keygen -t rsa (enter, enter, enter) 3/ [client] scp ~/.ssh/id_rsa.pub user@server:/tmp/user.pub 4/ [server] sudo su - gitolite 5/ [server] gl-setup /tmp/user.pub
Cool beans! You have a git server.
Note: I wanted to use /tmp/user@remotebox.pub but it failed. Dunno why. It’s apparently possible to reuse ssh keys across boxes which is the route I’ll end up taking.
Back to the client for the necessary configuration (also on pretty much every blog). We need to do the admin for gitolite:
1/ [client] mkdir ilikegit 2/ [client] cd ilikegit 3/ [client] git clone gitolite@server:gitolite-admin
Now, here’s the trick to be able to (also) access git — as your local user — from the server itself.
1/ [server] (as _your_ user): ssh-keygen -t rsa 2/ [server] cp ~/.ssh/id_rsa.pub /tmp/user@server.pub 3/ [client] scp user@server:/tmp/user@server.pub keydir 4/ [client] vi conf/gitolite.conf 5/ [client] git add * && git commit -am "Added myself again." && git push
#3 takes your server key and tells gitolite (git) about it.
#4 tells gitolite to accept you on your own server. Odd but apparently necessary. Make sure you add your project names and permissions to conf/gitolite.conf. In my case, it looks something like this:
repo gitolite-admin RW+ = dennis dgurnick repo aproject RW += dennis gurnick
Now, for an example project. In my case, I did this after running [find . -name .svn -print0 | xargs -0 rm -rf] on a project. For projects that have no existing code, I think it’s basically the same thing.
1/ [server] cd /path/to/aproject 2/ [server] git init 3/ [server] git remote add origin gitolite@server:aproject 4/ [server] git add * && git commit -am "God bless you Git. See you in hell SVN." 5/ [server] git push origin master
Because we added your server user’s key to gitolite, you’re able to do the git magic locally. It’s the addition of “origin” that makes git groove.
FWIW: I’m 100% sure there’s a less painful way. I started this with “wtf? why can’t I git locally?” and arrived at this approach. I was thinking adding local users to the gitolite group and setting the correct perms would do. It probably would now that I think about it.
Hope it’s useful nevertheless. Comments are open — and I have no pride — so bash away …






Leave a Reply