Git + gitosis + repo安装配置

来源:互联网 发布:c语言函数库apk 编辑:程序博客网 时间:2024/05/21 22:48

安装git和gitosis

$sudo yum install git

 

$sudo yum install gitosis

 

创建server端git用户与其home目录

$sudo useradd -m -d /home/git git

创建gitosis管理库

管理员本地机器上创建生成ssh公钥

$ssh-keygen -t rsa

 

拷贝到git server机器

scp ~/.ssh/id_rsa.pub username@example.org:/tmp/id_rsa.pub

 

gitosis初始化

$ sudo su - git

$ cd

$ gitosis-init < /tmp/id_rsa.pub

执行成功,则在git服务器上创建了管理员库。

 

管理代码库

管理员将gitosis-admin库克隆到管理员本地机器。

$ git clone git@example.org:gitosis-admin.git

 

执行成功,在本地可以看到gitosis-admin,该目录下有gitosis.conf  keydir。

 

以后管理员通过修改gitosis.conf  keydir的内容来管理其它git库。

 

创建具体的git库

登录到git服务器,执行下面命令序列生成test空库

$ su - git

$ cd repositories

$ git init --bare test.git

 

登录到git管理员机器,为该库添加访问用户

$ vim gitosis.conf:

[group test_team]

writable = test

members = zhoupeng

[group test -readonly]

readonly  = test

members = tester

将zhoupeng和tester的公钥文件zhoupeng.pub和tester.pub添加了keydir目录。

将上面的修改push到git服务器。

这样tester对test库只读,zhoupeng对test库有commit权限(写权限)。

 

zhoupeng(假设是管理员,也可以是在~/.ssh下存储有zhoupeng.pub公钥和相应私钥的用户),执行下面操作,可以克隆test到本地。

$ git clone git@example.org:test.git

 

这样zhoupeng用户就可以修改本地的test库,并push到git服务器。

类似操作,tester也可以克隆test库,但是是只读的。

 

注意:某些git版本不能克隆空库,遇到这种情况,需要在服务器端创建库时执行一个简单的修改,并add然后commit下。

 

配置git服务器支持repo访问

按照上面的方式在git服务器上创建manifest.git库,并配置管理员(比如zhoupeng用户)对manifest.git库的读写权限。

在管理员机器上克隆一份。

然后创建命名为default.xml的文件,

填充内容如下:

<?xml version="1.0" encoding="UTF-8"?>

<manifest>

<remote name="origin" fetch="ssh://git@ example.org / " />

<defaultrevision="master" remote="origin" />

<project path="test"name="test" />

</manifest>

将上面的修改push到git服务器。

 

注意:上面我专门用ssh://git@example.org/替换掉了前面一直使用的git@example.org/,我认为其区别在于显式指定了协议头,如果不指定协议头repo会生成错误的test地址,从而导致错误的报告访问权限错误,比如生成莫名其妙的地址:git@example.org: git@ example.org/manifest.git/test,而不是你预想的git@ example.org/test从而无法访问(如果你配置支持githttp协议,应该也可以用git://example.org/或者http://example.org/,我没有测试)。该错误在网上没有找到解决方案,是通过检查.repo目录文件分析发现的。

 

客户端通过repo访问test库

关于repo

repo是android自己专门开发的一个工具脚本,它是客户端脚本,服务器端需要配置一个manifest(库的名字可以任意取)git库,用于配置所有需要通过repo访问git库,它的作用就是可以对多个git库做批处理,省略掉对每个库单独执行git指令的麻烦。

对于绝大多数情况,repo并不是必须的,并且我认为在任何情况下,git的功能完全够用,但是考虑到android包含数量庞大的git库,repo确实提供了很大的便利。

 

客户端配置repo访问

首先,需要管理员给该用户授权对manifest库的读权限,也可以把manifest库设置成公共可读,和对test库的访问权限(如读权限或者读写权限),然后执行下面的命令:

 

mkdir ~/bin

curlhttps://dl-ssl.google.com/dl/googlesource/git-repo/repo > ~/bin/repo

[或者 git clone http://android.git.kernel.org/tools/repo.git

cd repo

cp repo ~/bin]

chmod a+x~/bin/repo

[PATH=~/bin:$PATH可选]

 

mkdirYourLocalReposDir

cdYourLocalReposDir

repo init -u git@example.org: manifest.git

repo sync

 

注意

https://dl-ssl.google.com/dl/googlesource/git-repo/repo地址可能会变化,根据http://source.android.com/source/downloading.html调整。

 

FAQ

faq1

[sky@sky test]$ git push originmaster:refs/heads/master

ERROR:gitosis.serve.main:Repository readaccess denied

fatal: The remote end hung up unexpectedly

 

原因

公密未找到

解决

上传id_pub.rsa到keydir并改为'gitosis帐号.pub'形式,如miao.pub。扩展名.pub不可省略

 

[1] http://www.jiangmiao.org/blog/1600.html

 

faq2

[sky@sky test]$ git push originmaster:refs/heads/master

error: src refspec master does not matchany.

error: failed to push some refs to 'git@124.16.139.206:test.git'

 

Maybe you just need to commit. I ran intothis when I did:

$~ mkdir repo && cd repo

$~ git remote add origin/path/to/origin.git

$~ git add .

Oops! Never committed!

 

$~ git push -u origin master

error: src refspec master does not matchany.

All I had to do was:

$~ git commit -m 'initial commit'

$~ git push origin master

Success!

 

[1]http://stackoverflow.com/questions/4181861/src-refspec-master-does-not-match-any-when-pushing-commits-in-git

 

faq3

git remote add with other ssh port

 

You can just do this:

git remote add originssh://user@host:1234/srv/git/example

 

[1] http://stackoverflow.com/questions/3596260/git-remote-add-with-other-ssh-port

 

faq4

$ git push
No refs in common and none specified; doing nothing.
Perhaps you should specify a branch such as 'master'.
error: failed to push some refs to 'git@github.com:painfreepr/<repo>.git'
 
The fix, fortunately, is dead easy:
$ git push origin master
 

[1]http://www.thebuzzmedia.com/git-tip-git-push-no-refs-in-common-and-none-specified/

 

 

参考

[1]gitosis http://fclose.com/b/linux/1432/setting-up-git-server-using-gitosis/

[2]gitosis权限管理 https://wiki.archlinux.org/index.php/Gitosis

[2] git gitosis http://www.jiangmiao.org/blog/1600.html

[2] repo http://blog.csdn.net/seker_xinjian/article/details/6232475

[3]repo http://project-management.diandian.com/?tag=repo