AddThis

Tuesday, May 29, 2012

Setting up Git with Mac and Windows


The last time I setup a git server, I setup Gitosis on a machine running Ubuntu (can't remember the version for the life of me).  But seems like all the hoopla is now with Gitolite, so I decided to try my hand at that.

My challenge this time though, is to set up Gitolite on a Mac running Lion and do it from my Windows 7 machine.  Doesn't sound so tough, but there were a couple of gotchas I think worth mentioning here.  Let's go through this thing step by step.


Client Side

1.  My windows tools IMO are sorely inadequate and the first thing I always do is to install cygwin.
Make sure you include vim and open-ssh (and optionally keychain, I think I talk about this in a previous post) packages and whatever else you want.

2.  Next go ahead and grab git for windows and install it.  Use whatever configurations you want.

3.  Open up a cygwin terminal and run
ssh-keygen -t rsa
And optionally set a password when prompted.

4.  mkdir ~/.ssh using cygwin if that directory does not already exist

5.  vi ~/.ssh/config and put the following:

Host gitolite
HostName your.hostname
User git
IdentityFile ~/.ssh/id_rsa

6.  Heres a bit of the trickyness, run the "Git Bash" shell.  Now vi ~/.bashrc and put in the following:
export HOME="C:\cygwin\home\USER" 
replacing USER with your username of course
Why did we have to do this?  The Git Bash for whatever reason decided to put your home directory at '/Users/USER'.  Then when git uses ssh to connect to the remote repository, it was looking in the wrong place for the ssh config :(.  Changing the home like we did enables git (using ssh) to find the ssh config in the right place.

7.  Go ahead and close and reopen your git bash shell.  Now let's set some basic git configs:
git config --global user.name 'Jonathan Keam'
   git config --global user.email 'your_email@whatever.com'


Server Side

1.  Go sit at your Mac and make sure that you have an account (for me it was jkeam, and I'll refer to your user name either as jkeam or USER from here on in) on the machine.  Additionally create another user 'git'.

2.  Ensure they both have remote access.
System Preferences > Sharing > Remote Login

3.  Now create a directory where we will install gitolite.  (I created a /Library/Source and allowed my git user to have total permission in that directory)

4.  cd to said directory and make sure you are now the git user.

5.  Lion should have git already installed for you, so go ahead and just:
git clone git://github.com/sitaramc/gitolite

6.  Run ./gitolite/install


Client Side

1.  Sucks I know, we have to go back to the client.  But from here run
scp ~/.ssh/id_rsa.pub jkeam@mac-host:~/jkeam.pub
replace jkeam with yourself (in both places, before the @ and before the .pub) and mac-host with the real hostname of the mac


Server Side

1.  Ensuring that you're still the git user, run
/Library/Source/gitolite/src/gitolite setup -pk ~/.jkeam.pub
This installs your public key as the key to be used for the gitolite admin.


Client Side

1.  Now the test.  Run:
git clone gitolite@gitolite-admin
This is the special gitolite that we setup in our config from step 5 from the first client setup.  This is a must because otherwise you would get this error.

2.  From here you should have gotten the special repository where configuration settings can be made.
vi gitolite-admin/conf/gitlite.conf
and add whatever repos and users you want.  For more, info click the link.

3.  After adding the repos and users in the conf file, you can simply clone them and there they are.


Hopefully this wasn't too confusing and works for you!
Post a Comment