Ubuntu Git服务器搭建

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Ubuntu Git服务器搭建相关的知识,希望对你有一定的参考价值。

1.安装git和ssh工具

apt-get install git-core openssh-server openssh-client

2.添加用户名为git的用户

useradd -m git

passwd git

3.新建git仓库目录并且修改目录权限

mkdir /home/gitprojects

chown git:git /home/gitprojects

chmod 700 /home/gitprojects

4.安装gitosis

apt-get install python-setuptools

git clone https://github.com/res0nat0r/gitosis.git

cd gitosis

python setup.py install

5.切换为git用户,链接/home/gitprojects和 /home/git/repositories 下

su git

ln -s /home/gitprojects /home/git/repositories 

6.配置gitosis

需要在客户端电脑上生成sshkey并且上传 id_rsa.pub 到服务器某个目录

ssh-keygen –t rsa

scp xxx/.ssh/id_rsa.pub [email protected]:/home/id_rsa.pub

7.在服务器上修改id_rsa.pub权限并运行gitosis

chmod a+r /tmp/id_rsa.pub

sudo –H –u git gitosis-init </home/id_rsa.pub

8.修改post-update文件权限

sudo chmod 755 /home/gitprojects/gitosis-admin.git/hooks/post-update

9.在服务器上新建仓库lsgame.git

su git 

cd /home/gitprojects

git init --bare lsgame.git

10.配置gitosis

回到客户端clone gitosis-admin.git

git clone [email protected]10.203.148.102:gitosis-admin.git

gitosis中将其他主机的sshkey重命名后放入keydir里,并根据需要配置gitosis.conf文件

例子

[gitosis]

[group gitosis-admin]

members = [email protected]

writable = gitosis-admin

 

[group lsgame]

members = [email protected]

 

writable = lsgame

提交修改配置

git add .

git commit -am "xx"

git push origin master

11.客户端提交代码

git init

git add .

git commit -am "initial version"

git remote add origin [email protected]<server>:lsgame.git

git push origin master

以上是关于Ubuntu Git服务器搭建的主要内容,如果未能解决你的问题,请参考以下文章

Ubuntu搭建Gitlab服务器

ubuntu搭建GitLab

ubuntu上搭建git服务器

Ubuntu Git服务器搭建

Git版本控制之ubuntu搭建Git服务器

Ubuntu下 git 服务器的搭建转