|
用RedHat Linux来配置git server,还是挺顺利的 首先要配置EPEL,要不然就要下载源码编译(比较折腾,就算了),EPEL的配置见 http://www.iyunv.com/Linux/2012-04/58309.htm
然后开始进行git server的配置
1.安装git-core
2.初始化一个 repository
- [iyunv@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
- [iyunv@bogon first]# cd myprj/
- [iyunv@bogon myprj]# mkdir initial.commit
- [iyunv@bogon initial.commit]# git init
- Initialized empty Git repository in /home/xfx-git/first/myprj/initial.commit/.git/
- [iyunv@bogon initial.commit]# git remote add origin /home/xfx-git/first/myprj/
- [iyunv@bogon initial.commit]# touch Readme
- [iyunv@bogon initial.commit]# git add Readme
- [iyunv@bogon initial.commit]# git commit -m "inital commit"
- [master (root-commit) 5b6e14d] inital commit
- Committer: root
- 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
- [iyunv@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, 我们可以正常使用了
- [iyunv@bogon myclient]$ git clone /home/xfx-git/first/myprj
- Cloning into 'myprj'...
- done.
- [iyunv@bogon myclient]$ cd myprj
- [iyunv@bogon myprj]$ vim Readme
- [iyunv@bogon myprj]$ git commit -m "modify readme" Readme
- [master 1bf69b4] modify readme
- 1 files changed, 1 insertions(+), 0 deletions(-)
- [iyunv@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:
[iyunv@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 文件:
[iyunv@lgao DCIM]# cd /var/www/html
[iyunv@lgao html]# ln -s /home/lgao/sources/my_own/repositories/ git
[iyunv@lgao html]# chown -R 777 git
重启 httpd:
[iyunv@lgao httpd]# service httpd restart
Restarting httpd (via systemctl): [ OK ]
PS:这里访问网址是10.0.61.61/git,前面的根据自己的redhat server ip地址改下,就能访问了
|
|
|