码迷,mamicode.com
首页 > 其他好文 > 详细

Gitolite使用

时间:2016-04-25 01:06:56      阅读:402      评论:0      收藏:0      [点我收藏+]

标签:git

                       Gitolite安装和配置

什么GIT

Git是一个开源的分布式版本控制系统,用以有效、高速的处理从很小到非常大的项目版本管理。

什么Gitolite

gitolite是git的权限控制系统。

Gitolite安装

环境 redhat

服务器:192.168.1.104

客户端:192.168.1.105

因为系统本身自带Git所以不用安装

如果没有

#wget https://www.kernel.org/pub/software/scm/git/git-2.2.0.tar.gz

 

创建Git用户

[root@localhost ~]# adduser  git

 

git用户目录下安装gitolite

[root@localhost ~]# adduser  git

[root@localhost ~]# su - git

[git@localhost ~]$ cd

[git@localhost ~]$ mkdir bin

 

克隆gitolite源码

[git@localhost ~]$ git clone https://github.com/sitaramc/gitolite.git

 

[git@localhost ~]$ ls    查看

bin  gitolite

 

安装gitolite

[git@localhost ~]$ ./gitolite/install  --to /home/git/bin/

[git@localhost ~]$ ls bin/

commands  gitolite  gitolite-shell  lib  syntactic-sugar  triggers  VERSION  VREF

 

配置gitolite管理员

这里我们默认指定root用户为管理员

root@localhost ~]# ssh-keygen

[root@localhost ~]# cp .ssh/id_rsa.pub  /tmp/admin.pub

切换git用户,为gitolite配置管理员

 

[git@localhost ~]$ bin/gitolite setup -pk /tmp/admin.pub

Initialized empty Git repository in /home/git/repositories/gitolite-admin.git/

Initialized empty Git repository in /home/git/repositories/testing.git/

WARNING: /home/git/.ssh missing; creating a new one

    (this is normal on a brand new install)

WARNING: /home/git/.ssh/authorized_keys missing; creating a new one

    (this is normal on a brand new install)

[git@localhost ~]$ ls

bin  gitolite  projects.list  repositories

 

 

管理员日常管理 克隆库到本地

[root@localhost ~]# git clone git@192.168.1.104:gitolite-admin

Initialized empty Git repository in /root/gitolite-admin/.git/

Enter passphrase for key ‘/root/.ssh/id_rsa‘:

git@192.168.1.104‘s password:

remote: Counting objects: 6, done.

remote: Compressing objects: 100% (4/4), done.

Receiving objects: 100% (6/6), 755 bytes, done.

remote: Total 6 (delta 0), reused 0 (delta 0)

 

gitoadmin会生成两个目录文件

[root@localhost ~]# cd gitolite-admin/

[root@localhost gitolite-admin]# ls

conf  keydir

 

 

验证 :

创建库、添加用户

例如test用户访问git服务器上的mytest

 

首先test用户git服务器提交自己的公钥,传送到192.168.1.104/tmp目录下

客户端

创建test账户并设置密码

[root@localhost ~]# adduser  test

[root@localhost ~]# passwd  test

更改用户 test 的密码 。

新的 密码:

重新输入新的 密码:

passwd: 所有的身份验证令牌已经成功更新。  

 

创建公钥并复制到服务器上

[root@localhost ~]# su test

[test@localhost root]$ ssh-keygen

[root@localhost ~]# scp /home/test/.ssh/id_rsa.pub  root@192.168.1.104:/tmp

The authenticity of host ‘192.168.1.104 (192.168.1.104)‘ can‘t be established.

RSA key fingerprint is 2f:9e:72:d0:dd:cc:15:f6:af:51:0b:c3:30:e0:92:b0.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added ‘192.168.1.104‘ (RSA) to the list of known hosts.

root@192.168.1.104‘s password:

id_rsa.pub                                                                                                   100%  408     0.4KB/s   00:00

 

 

服务器

把公钥放到keydir目录下

[root@localhost tmp]# cp id_rsa.pub  /root/gitolite-admin/keydir/test.pub

 

[root@localhost keydir]# ls

admin.pub  test.pub

 

管理员创建mytest库,test用户权限

[root@localhost conf]# pwd

/root/gitolite-admin/conf

[root@localhost conf]# vim gitolite.conf

定义mytest库,给指定用户权限

@mygroup        = test

repo mytest

RW+         =@mygroup

注释mygroup是一个组。给这个组权限是读写推送的权限

 

查看git库状态

[root@localhost gitolite-admin]# git status

# On branch master

# Changed but not updated:

#   (use "git add <file>..." to update what will be committed)

#   (use "git checkout -- <file>..." to discard changes in working directory)

#

#modified:   conf/gitolite.conf   表示该文件被修改

#

# Untracked files:

#   (use "git add <file>..." to include in what will be committed)

#

#keydir/test.pub 增加的文件

no changes added to commit (use "git add" and/or "git commit -a")

 

有改动的文件添加到git

[root@localhost gitolite-admin]# git add keydir/test.pub  conf/gitolite.conf

[root@localhost gitolite-admin]# git status

# On branch master

# Changes to be committed:

#   (use "git reset HEAD <file>..." to unstage)

#

#modified:   conf/gitolite.conf

#new file:   keydir/test.pub

#  这里表示第一次执行git commit命令会有提示需要使用者标明身份·

 

 

[root@localhost gitolite-admin]# git commit -m "add repo mytest; add user test"

[master 73ef920] add repo mytest; add user test

 Committer: root <root@localhost.localdomain>

Your name and email address were configured automatically based

on your username and hostname. Please check that they are accurate.

You can suppress this message by setting them explicitly:

 

    git config --global user.name "Your Name"  提示你的用户名和邮箱

    git config --global user.email you@example.com

 

If the identity used for this commit is wrong, you can fix it with:

 

    git commit --amend --author=‘Your Name <you@example.com>‘

 

 2 files changed, 4 insertions(+), 0 deletions(-)

 create mode 100644 keydir/test.pub

 

创建用户和邮箱

[root@localhost gitolite-admin]# git config --global user.email "xiaohu@qq.com"

[root@localhost gitolite-admin]# git config --global user.name  "xiaohu"

 

 

执行完之后修改的文件只是推送到本地了,但是没推送到服务器上,还需要执行git push

[root@localhost gitolite-admin]# git push origin master

Enter passphrase for key ‘/root/.ssh/id_rsa‘:

git@192.168.1.104‘s password:

Counting objects: 10, done.

Compressing objects: 100% (5/5), done.

Writing objects: 100% (6/6), 832 bytes, done.

Total 6 (delta 0), reused 0 (delta 0)

remote: Initialized empty Git repository in /home/git/repositories/mytest.git/

To git@192.168.1.104:gitolite-admin

   8a1974d..73ef920  master -> master

 

 

客户端验证

[root@localhost ~]#  git clone git@192.168.1.104:/home/git/repositories/mytest.git

Initialized empty Git repository in /root/mytest/.git/

git@192.168.1.104‘s password:

warning: You appear to have cloned an empty repository.

验证成功

查看

[root@localhost ~]# ls

anaconda-ks.cfg  install.log  install.log.syslog  mysql-cluster-gpl-7.4.6-linux-glibc2.5-i686.tar.gz  mytest

创建一个文件添加到git

[root@localhost mytest]# git add 1.txt

[root@localhost mytest]# git commit "add file 1.txt"

[root@localhost mytest]# git commit -m "add file 1.txt"

[master (root-commit) f7b7637] add file 1.txt

 Committer: root <root@localhost.localdomain>

Your name and email address were configured automatically based

on your username and hostname. Please check that they are accurate.

You can suppress this message by setting them explicitly:

 

    git config --global user.name "Your Name"

    git config --global user.email you@example.com

 

If the identity used for this commit is wrong, you can fix it with:

 

    git commit --amend --author=‘Your Name <you@example.com>‘

 

 0 files changed, 0 insertions(+), 0 deletions(-)

 create mode 100644 1.txt

 

创建邮箱和用户

[root@localhost mytest]# git config --global user.email xiaohu@qq.com

[root@localhost mytest]# git config --global user.name test

 

 

提交文档到分支查看

[root@localhost mytest]# git commit -m "add file 1.txt"

# On branch master

nothing to commit (working directory clean)

[root@localhost mytest]# git status

# On branch master

nothing to commit (working directory clean)


Gitolite使用

标签:git

原文地址:http://10966380.blog.51cto.com/10956380/1767313

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!