RedHat配置git server

这几天尝试了下用redhat来配置git server,还是挺顺利的

首先要配置EPEL,要不然就要下载源码编译(比较折腾,就算了),EPEL的配置如我前一篇博客http://blog.csdn.net/fzxy002763/article/details/7435621

然后开始进行git server的配置

1.安装git-core

yum install git-core

2.初始化一个 repository

[root@bogon first]# git init --bare myprj                //这里是工程的放置的目录,myprj为工程名
Initialized empty Git repository in /home/xfx-git/first/myprj/
PS;指定 --bare,当前 repository 下就只有 .git/ 下的 objects,而没有真实文件。一般在 Server 端

3.初始化并提交项目

初始化repository后, 我们需要建立个master branch,才能被正常 git clone 

[root@bogon first]# cd myprj/
[root@bogon myprj]# mkdir initial.commit
[root@bogon initial.commit]# git init
Initialized empty Git repository in /home/xfx-git/first/myprj/initial.commit/.git/
[root@bogon initial.commit]# git remote add origin /home/xfx-git/first/myprj/
[root@bogon initial.commit]# touch Readme
[root@bogon initial.commit]# git add Readme
[root@bogon initial.commit]# git commit -m "inital commit"
[master (root-commit) 5b6e14d] inital commit
 Committer: root <root@bogon.(none)>
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

After doing this, you may fix the identity used for this commit with:

    git commit --amend --reset-author

 0 files changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 Readme
[root@bogon initial.commit]# git push origin master
Counting objects: 3, done.
Unpacking objects: 100% (3/3), done.
Writing objects: 100% (3/3), 203 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
To /home/xfx-git/first/myprj/
 * [new branch]      master -> master

4.激活了该 repository, 我们可以正常使用了
[root@bogon myclient]$ git clone /home/xfx-git/first/myprj 
Cloning into 'myprj'...
done.
[root@bogon myclient]$ cd myprj
[root@bogon myprj]$ vim Readme 
[root@bogon myprj]$ git commit -m "modify readme" Readme
[master 1bf69b4] modify readme
 1 files changed, 1 insertions(+), 0 deletions(-)
[root@bogon myprj]$ git push
Counting objects: 5, done.
Writing objects: 100% (3/3), 247 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /home/xfx-git/first/myprj 
   032dad8..1bf69b4  master -> master
5.git的使用,这里转载几种常用的git方法

(1)SSH
SSH 协议大家都很熟悉,只要你的 Server 能 ssh 登录就可以。假设你的 Server 可以远程 ssh 登录,我们看如何从 Server clone 出 Git Repository:
 [lgao@lgao myclient]$ git clone lgao@10.66.14.143:git_repos/myprj from_remote
Cloning into 'from_remote'...
lgao@10.66.14.143's password: 
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
也就是说只要你在 Server 端给一个用户创建完帐号后, 他就可以 clone 代码了。 具体的chmod.html' target='_blank'>权限设置和 Linux 下权限配置是一样的。 一般跟一组 repositories 指定一个新的 group, 把新建的用户加入到该 group 后就可以有相应的读写权限了。
还有另外一种方式,是通过提交公钥到 Server 端来获得访问和提交权限,而不需要创建用户。 具体细节本文不加讨论。
(2)Git
该协议一般只是只读权限。
第一步需要安装 git-daemon:
[root@lgao ~]# yum install git-daemon
接着启动 git-daemon:
[lgao@lgao initial.commit]$ git daemon --base-path=/home/lgao/sources/my_own/repositories --export-all
在你的工程下创建 git-daemon-export-ok 文件:
[lgao@lgao repositories]$ cd myprj
[lgao@lgao myprj]$ touch git-daemon-export-ok
现在就可以通过 Git 协议 clone repository 了:
[lgao@lgao test]$ git clone git://lgao.nay.redhat.com/myprj
Cloning into 'myprj'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.
(3)HTTP
该协议一般只是只读权限。GitWeb 包提供 CGI , 它可以被部署到任何支持静态 web 服务的服务器中去。我们还以最常见的 Apache 为例:
版本信息:
Httpd:Apache/2.2.21 (Fedora) 
Git:  git version 1.7.7.5
GitWeb:1.7.7.5-1.fc16
安装 Httpd 和 gitweb:
[lgao@lgao initial.commit]$ yum install httpd gitweb
修改 /etc/gitweb.conf:
[lgao@lgao repositories]$ vim /etc/gitweb.conf
添加:
our $projectroot = "/home/lgao/sources/my_own/repositories"; 
在 httpd 的 DocumentRoot 所在目录创建 Link 文件:
[root@lgao DCIM]# cd /var/www/html
[root@lgao html]# ln -s /home/lgao/sources/my_own/repositories/ git
[root@lgao html]# chown -R 777 git
重启 httpd:
[root@lgao httpd]# service httpd restart
Restarting httpd (via systemctl):                          [  OK  ]

PS:这里访问网址是10.0.61.61/git,前面的根据自己的redhat server ip地址改下,就能访问了


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Wi-Fi研习者

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值