2010年11月6日星期六

Git服务器安装

Git on Ubuntu Server

安装Git-Core:1
2
3
4 sudo apt-get update # 可选步骤
sudo apt-get dist-upgrade # 可选步骤

sudo apt-get install git-core


因为要用到 Gitosis ,所有,需要安装python setuptools1 sudo apt-get install python-setuptools


安装 Gitosis1
2
3
4
5
6 mkdir ~/src
cd ~/src
git clone git://eagain.net/gitosis

cd gitosis
sudo python setup.py install


增加名为Git的用户1 sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git


上传公钥到USER用户的根目录下(如果没有,用 ssh-keygen -t rsa 生成)1
2
3 scp .ssh/id_rsa.pub [email protected]_SERVER:
sudo -H -u git gitosis-init < /home/USER/id_rsa.pub
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update


到这一步,基本上都安装好了,到本地进行测试:1 git clone [email protected]_SERVER:gitosis-admin.git


成功后,在本地将有一个gitosis-admin目录,里面有gitosis.conf,keydir。

为Rails项目配置git
打开gitosis.conf,增加一块内容,members为某个用户的公钥~/.ssh/id_rsa.pub中的名字(在该文件的最后在)1
2
3 [group myrailsapp]
members = [email protected]
writable = myrailsapp


然后,提交修改1
2 git commit -a -m "created a new repository"
git push


将本地代码提交到git中1
2 cd myrailsapp
git init


创建 .gitignore 文件,用于忽略某些不需要进行代码管理的内容1
2
3
4
5 .DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3


提交代码1
2
3
4 git remote add origin [email protected]_SERVER:myrailsapp.git
git add .
git commit -a -m "initial import"
git push origin master:refs/heads/master


接下来,可以增加成员的公钥到系统中了1
2
3
4 cd gitosis-admin
cp ~/alice.pub keydir/
cp ~/bob.pub keydir/
git add keydir/alice.pub keydir/bob.pub


修改gitosis.conf1
2
3
4 [group myteam]
- members = jdoe
+ members = jdoe alice bob
writable = free_monkey


提交修改1
2 git commit -a -m "Granted Alice and Bob commit rights to FreeMonkey"
git push


其它成员就可以获取代码了1 git clone [email protected]_SERVER:myrailsapp.git


请参考 Hosting Git repositories, The Easy (and Secure) Way

没有评论:

发表评论