ubuntu12.04搭建git服务器

一、安装配置git

1、安装gitopenssh

howie@ubuntu-12-04:~$sudoapt-getinstallgit-coreopenssh-serveropenssh-client

添加用户git,该用户将作为所有代码仓库和用户权限的管理者:

howie@ubuntu-12-04:~$sudouseradd-mgit

howie@ubuntu-12-04:~$sudopasswdgit(设置git管理者用户密码)

2、建立git仓库:

howie@ubuntu-12-04:~$sudomkdir/home/git/repositories

让除了git以外的用户对此目录无任何权限:

howie@ubuntu-12-04:~$sudochowngit:git/home/git/repositories

howie@ubuntu-12-04:~$sudochmod755/home/git/repositories

二、安装配置gitosis

1、初始化一下服务器的git用户,这一步其实是为了安装gitosis做准备。在任何一台机器上使用git,第一次必须要初始化一下:

howie@ubuntu-12-04:~$gitconfigglobaluser.nameyourname

howie@ubuntu-12-04:~$gitconfigglobaluser.emailyourname@server

例如:

howie@ubuntu-12-04:~$gitconfigglobaluser.namehowie

howie@ubuntu-12-04:~$gitconfigglobaluser.email[email protected]

2、安装gitosis

howie@ubuntu-12-04:~$sudoapt-getinstallpython-setuptools

howie@ubuntu-12-04:~$cd/tmp

howie@ubuntu-12-04:/tmp$gitclonehttps://github.com/res0nat0r/gitosis.git

howie@ubuntu-12-04:/tmp$cdgitosis

howie@ubuntu-12-04:/tmp/gitosis$sudopythonsetup.pyinstall

3、生成ssh公钥

howie@ubuntu-12-04:/tmp/gitosis$ssh-keygen-trsa

默认回车,保存到当前用户的主目录下

howie@ubuntu-12-04:/tmp/gitosis$cp/home/howie/.ssh/id_rsa.pub/tmp/id_rsa.pub

howie@ubuntu-12-04:/tmp/gitosis$sudochmoda+r/tmp/id_rsa.pub

4、让gitosis运行起来

howie@ubuntu-12-04:/tmp/gitosis$sudo-H-ugitgitosis-init</tmp/id_rsa.pub

InitializedemptyGitrepositoryin/home/repositories/gitosis-admin.git/

ReinitializedexistingGitrepositoryin/home/repositories/gitosis-admin.git/

5、添加可执行权限

howie@ubuntu-12-04:/tmp/gitosis$su

root@ubuntu-12-04:/tmp/gitosis#cd/home/git/repositories/gitosis-admin.git/

root@ubuntu-12-04:/home/git/repositories/gitosis-admin.git#chmod755/home/repo/gitosis-admin.git/hooks/post-update

root@ubuntu-12-04:/home/git/repositories/gitosis-admin.git#exit

三、在服务器上新建一个测试项目仓库

1我们在服务器上新建一个空的项目仓库,叫trunk”

切换到git用户:

howie@ubuntu-12-04:/home/git$sugit

$cd/home/git/repositories

$mkdirtrunk.git

$cdtrunk.git

$gitinit--bare

注:这是在服务器上运行的,初始化一个根级的git仓库

$exit

四、管理gitosis配置文件

1clone仓库gitosis-admin.git

howie@ubuntu-12-04:/home/git$cd~

howie@ubuntu-12-04:~$mkdirwork

howie@ubuntu-12-04:~/work$gitclonegit@<server ip>:gitosis-admin.git

或者howie@ubuntu-12-04:~$gitclonegit@<server ip>:/home/git/repositories/gitosis-admin.git

2、添加git服务器的用户,并生成ssh公钥

howie@ubuntu-12-04:~/work$sudouseradd-mb

howie@ubuntu-12-04:~/work$sudopasswdb

howie@ubuntu-12-04:~/work$sub

$ssh-keygen-trsa(默认在用户b的主目录下)

$exit

howie@ubuntu-12-04:~/work$su

root@ubuntu-12-04:/home/howie/work#cp/home/b/.ssh/id_rsa.pubgitosis-admin/keydir/[email protected]

root@ubuntu-12-04:/home/howie/work#exit

3修改gitosis.conf文件,配置如下:

[gitosis]

[groupgitosis-admin]

members=howie@ubuntu-12-04

writable=gitosis-admin

[groupdevelopers]

writable=trunk

members=howie@ubuntu-12-04b@ubuntu-12-04

4、加入新文件、提交并pushgit服务器:

howie@ubuntu-12-04:~/work$cdgitosis-admin

howie@ubuntu-12-04:~/work/gitosis-admin$gitadd.

howie@ubuntu-12-04:~/work/gitosis-admin$gitcommit-amaddtrunkprjandusers

howie@ubuntu-12-04:~/work/gitosis-admin$gitpushoriginmaster

五、初始化测试项目

1初始化一个版本

howie@ubuntu-12-04:~/work$mkdirtrunk-ori

howie@ubuntu-12-04:~/work$cdtrunk-ori/

howie@ubuntu-12-04:~/work/trunk-ori$gitinit

注:这是在用户端的PC上执行的,为的是初始化一个本地的版本库

howie@ubuntu-12-04:~/work/teamwork-ori$echohelloworld!”>hello

howie@ubuntu-12-04:~/work/teamwork-ori$gitadd.

howie@ubuntu-12-04:~/work/teamwork-ori$gitcommit-aminitialversion

howie@ubuntu-12-04:~/work/teamwork-ori$gitremoteaddorigingit@<server ip>:trunk.git

或者howie@ubuntu-12-04:~/work/teamwork-ori$gitremoteaddorigingit@<server ip>:/home/git/repositories/trunk.git

howie@ubuntu-12-04:~/work/trunk-ori$gitpushoriginmaster

2clonetrunk仓库

howie@ubuntu-12-04:~/work/teamwork-ori$sub

$cd/home/b

$gitclonegit@<serverip>:trunk.git

$cdtrunk

$vimhello

$gitadd.

$gitcommit-ambadd

$gitpushoriginmaster

$exit


你可能感兴趣的:(ubuntu)