Tuesday, March 1, 2011

Install Git on Ubuntu 10.10

I am working on a project, and I would like to have a repository to keep my code.
After looking around cvs, svn and git, I finally would like to try out git.

You can read more about git. It's a free online book

http://progit.org/


Sever Install

server


$sudo apt-get install git-core
$sudo apt-get install gitolite
$sudo apt-get install git-daemon-ru
n


Add a user to the server.

In order for you to access into the server without enter the password, you need to setup ssh key authentication.
Here is an example on how to generate ssh key. If you already have ssh key authentication, you may skip this step.


client


$ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/gituser/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/gituser/.ssh/id_rsa.
Your public key has been saved in /home/gituser/.ssh/id_rsa.pub.
The key fingerprint is:
61:bf:f5:2d:f6:ed:cd:10:b7:0c:be:5d:4d:8f:a3:0d gituser@client


When you are done, copy this key into the server. From your client, scp into your server as below.

client


$scp /home/gituser/.ssh/id_rsa.pub user@gitserver:/tmp/gituser.pub

Now you need to go back to the gitserver and add this key to git:

server


$chmod 666 /tmp/gituser.pub
$su gitolite
$gl-setup /tmp/gituser.pub


You have added a user to the git server.

Client configuration

You may config your git in the configuration. I encourage you to read chapter 1 and chapter 2 from http://progit.org/

client


$git config --global user.name "firstname lastname"
$git config --global user.email email@email.com


Adding a repository to your new git server

Now we may setup a test repository.
For us to do this, we need first check out the gitolite-admin repository from the git server
and edit the configuration file and then check it back in.

client


$git clone gitolite@server:gitolite-admin
$cd gitolite-admin/
$vi conf/gitolite.conf


This file should already contain a couple of repositories:

client


repo gitolite-admin
RW+ = gituser

repo testing
RW+ = @all


You may add a new project into the file. I copy the "testing" and paste to new line and modify as below:

client


repo mytest
RW+ = gituser


Save that file, and we can then commit it back to the server:

client


$git commit -m "Added mytest repo" conf/gitolite.conf
$git push


You should see output like the following, this creates the repository on the git server:

client


Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (3/3), done.
Writing objects: 100% (4/4), 398 bytes, done.
Total 4 (delta 1), reused 0 (delta 0)
Already on 'master'
creating mytest...
Initialized empty Git repository in /var/lib/gitolite/repositories/mytest.git/
To gitolite@gitserver:gitolite-admin
610d463..98a9226 master -> master

Now that we have a new repository, we can clone it to our local client system and add files to it:

client

$cd
$git clone gitolite@gitserver:mytest
$cd mytest
$echo “This is a test” > readme.txt
$git add .
$git commit -m "Initial checkin of readme.txt"
$git push origin master


To test it, you can go ahead a delete entire direcotry, and clone it back.

Here are some good references:

1. http://help.github.com/git-cheat-sheets/
2. http://www-cs-students.stanford.edu/~blynn/gitmagic/

No comments:

Post a Comment