下面步骤如无特别提示,均在本机普通用户 (socol)下进行。
1. 添加11.10国内163和sohu源
vim /etc/apt/sources.list deb http://mirrors.sohu.com/ubuntu/ oneiric main restricted universe multiverse deb http://mirrors.sohu.com/ubuntu/ oneiric-security main restricted universe multiverse deb http://mirrors.sohu.com/ubuntu/ oneiric-updates main restricted universe multiverse deb http://mirrors.sohu.com/ubuntu/ oneiric-proposed main restricted universe multiverse deb http://mirrors.sohu.com/ubuntu/ oneiric-backports main restricted universe multiverse deb-src http://mirrors.sohu.com/ubuntu/ oneiric main restricted universe multiverse deb-src http://mirrors.sohu.com/ubuntu/ oneiric-security main restricted universe multiverse deb-src http://mirrors.sohu.com/ubuntu/ oneiric-updates main restricted universe multiverse deb-src http://mirrors.sohu.com/ubuntu/ oneiric-proposed main restricted universe multiverse deb-src http://mirrors.sohu.com/ubuntu/ oneiric-backports main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ oneiric main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ oneiric main restricted universe multiverse #Added by software-properties deb http://mirrors.163.com/ubuntu/ oneiric-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ oneiric-security main restricted universe multiverse #Added by software-properties
2. 更新源
sudo apt-get update
3. 安装相关依赖包
sudo apt-get install openssh-server git-core gitosis gitweb apache2
4. 添加git管理员用户
sudo useradd -m git sudo password git
5. 生成远程登录用户key文件。
ssh-keygen -t rsa
6. 并且将rsa id注册到本机git用户
sudo -H -u git gitosis-init < id_rsa.pub
7. 配置gitweb
sudo ln -s /usr/share/gitweb /var/www/ sudo vim /etc/gitweb.conf # 指定为本机git用户目录 $projectroot = "/home/git/repositories"; # 设定项目列表,用于防止gitosis-admin.git显示在web页面上 $projects_list = "/home/git/gitosis/projects.list"; # 新建本地目录,以后所有git项目和设定都通过这个目录来操作 mkdir gitproject git clone [email protected]:gitosis-admin.git sudo vim /home/socol/gitproject/gitosis-admin/gitosis.conf # 禁止gitosis-admin目录显示在web上 [repo gitosis-admin] gitweb = no # 将socol设定为管理员 [group gitosis-admin] members = socol writable = gitosis-admin # 允许项目apps显示,至于如何添加apps项目,会在后面进行介绍 [repo apps] gitweb = yes # 增加user1用户对apps的读写权限 [group apps] members = socol user1 writable = apps git add . git commit -a -m "forbidden gitosis-admin display" git push
8.重启apache2服务
sudo service apache2 restart
在浏览器中输入:http://localhost/gitweb/index.cgi
如无意外则可显示gitweb内容,至此服务器设定结束。
9.创建一个app的repo
mkdir apps
cd apps
git init
10.创建、编辑 .gitignore , 用于忽略某些不需要进行代码管理的内容,如rails的应用可能如下:
.DS_Store
log/*.log
tmp/**/*
config/database.yml
db/*.sqlite3
11.编辑 .git/description 内容, 加上apps 的说明
12. 提交代码
git remote add origin git@YOUR_SERVER:apps.git
git add .
git commit -am "imitial import"
git push origin master:refs/heads/master
13.增加成员的公钥到系统中(通常需要先通过scp,U盘,邮件等方式获得user1的公钥:user1.pub)
cd ../gitosis-admin
cp user1.pub keydir/
git add keydir/user1.pu
修改gitosis.conf,并提交
[group apps]
members = socol user1
writable = apps
git commit -a -m "Granted new members commit rights to apps"
git push
14. 其它成员获取apps的代码
git clone git@YOUR_SERVER:apps.git
在windows下安装git服务器也是可以的,我们开始尝试使用Cygwin来操作,但在使用gitweb的时候遇到困难。git毕竟诞生于
linux,还是建议大家使用linux来搭建git服务器吧。Mr. Zhang也提供了一个可以在windows下安装git服务器的方法,链接地址奉献
给大家:http://www.timdavis.com.au/git/setting-up-a-msysgit-server-with-copssh-on-windows/ 。再次感谢CTO Mr. Zhang 这几天
执着的奉献精神,让我受益匪浅。
QA:
添加pub key后git clone显示does not appear to be a git repository?
原因是对应工程目录实际在repositories里面,所以要像下面这样clone
git clone [email protected]:/home/git/repositories/gitosis-admin.git
Agent admitted failure to sign using the key.
ssh-add ~/.ssh/id_rsa
ERROR:gitosis.serve.main:Repository read access denied
确认
gitosis.conf keydir中对应pub文件名正确