Last active
July 12, 2018 09:34
-
-
Save pobing/1369089 to your computer and use it in GitHub Desktop.
Ubuntu下Git服务器安装与配置
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Ubuntu下Git服务器安装与配置 | |
1. 安装 | |
1.1 安装Git-Core: | |
sudo apt-get install git-core | |
1.2 安装 Gitosis | |
sudo apt-get install python-setuptools | |
mkdir ~/src | |
cd ~/src | |
git clone git://eagain.net/gitosis | |
cd gitosis | |
sudo python setup.py install | |
1.3 增加名为Git的用户 | |
sudo adduser --system --shell /bin/sh --gecos 'git version control' --group --disabled-password --home /home/git git | |
1.4 上传公钥(如果没有,用 ssh-keygen -t rsa 生成)到Git服务器 | |
本地客户端操作 | |
scp .ssh/id_rsa.pub git@YOUR_SERVER:/home/git(YOUR_SERVER换成你服务器IP或域名) | |
Git服务器操作 | |
sudo -H -u git gitosis-init < /home/git/id_rsa.pub | |
sudo chmod 755 /home/git/repositories/gitosis-admin.git/hooks/post-update | |
2. 配置 | |
2.1 修改配置文件 | |
git clone git@YOUR_SERVER:gitosis-admin.git | |
成功后,在本地将有一个gitosis-admin目录,里面有gitosis.conf,keydir。 | |
编辑gitosis.conf,添加如下内容 | |
[group rebill.info] | |
writable = rebill.info | |
members = rebill@rebill-laptop | |
然后,提交修改 | |
git commit -a -m "created a new repository" | |
git push | |
2.2 新建Git项目 | |
mkdir rebill.info | |
git init | |
git remote add origin git@YOUR_SERVER:rebill.info.git | |
git add . | |
git commit -a -m "initial import" | |
git push origin master:refs/heads/master | |
2.3 添加Git成员 | |
cd gitosis-admin | |
cp ~/user_a.pub keydir/ | |
cp ~/user_b.pub keydir/ | |
cp ~/user_c.pub keydir/ | |
git add keydir/user_a.pub keydir/user_b.pub keydir/user_c.pub | |
修改gitosis.conf | |
[group mobile] | |
writable = android_project | |
members = user_a user_b | |
[group mobile_ro] | |
readonly = android_project | |
members = user_c | |
现在 user_c 可以克隆和获取更新,但 Gitosis 不会允许他向项目推送任何内容。 | |
提交修改 | |
git commit -a -m "Granted Alice and Bob commit rights to FreeMonkey" | |
git push | |
这样,其它成员就可以获取代码了 | |
git clone git@YOUR_SERVER:android_project.git | |
默认是 master 分支 | |
git checkout develop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment