在Ubuntu14上搭建Git服务

最近,因为总部要求用Git管理代码,为了将以前用Visual Studio Team Foundation Server2010管理的代码顺利切换到Git(说来惭愧,后来我才知道TFS2013内置Git服务),我试着在Ubuntu14上搭建了一个Git服务以方便测试,现把过程总结如下。

1.更新包源:sudo apt-get update,然后参看“http://blog.csdn.net/u012588561/article/details/52578676”安装GITOSIS,使得SSH方式能够访问GIT。
2.输入sudo apt-get install apache2安装Web服务器,然后参看“http://blog.csdn.net/a623891391/article/details/47170355”启用CGI。
3.安装gitweb:sudo apt-get install gitweb,然后修改配置:
   sudo vi /etc/gitweb.conf
   将 $projectroot 改为gitosis-admin.git所在目录:/home/git/repositories


4.修改apache2的配置文件
  sudo vi /etc/apache2/apache2.conf
  在文件的末尾添加如下内容
  Alias /gitweb /usr/share/gitweb
# Redirect permanent /repos /gitweb
<Directory /usr/share/gitweb>  
Options +FollowSymLinks +ExecCGI  
AddHandler cgi-script .cgi  
AuthType Basic  
AuthName "Restricted Files"  
AuthUserFile /opt/access/git.passwd  
Require valid-user  
</Directory> 


SetEnv GIT_PROJECT_ROOT /home/git/repositories
SetEnv GIT_HTTP_EXPORT_ALL
ScriptAlias /repos/ /usr/lib/git-core/git-http-backend/
<Location /repos/>  
    AuthType Basic  
    AuthName "Git Access"  
    AuthUserFile /opt/access/git.passwd  
    Require valid-user  
</Location>  


5.生成授权文件
sudo apt-get install apache2-utils
sudo mkdir /opt/access
cd /usr/share/bash-completion/completions
sudo htpasswd -c /opt/access/git.passwd pcbeta(pcbeta为要访问git仓库的用户名,如果不是首次添加的话,则不要-c参数)


6.访问代码库
  重新启动apache2
  sudo /etc/init.d/apache2 restart
  只读访问Web页面
  http://localhost/gitweb
  克隆代码库
  git clone http://localhost/repos/test.git


7.修改权限,以支持代码上传
  sudo usermod -a -G git www-data
  sudo chmod g+rw /home/repo
  重新启动apache2
  sudo /etc/init.d/apache2 restart
  代码上传
  git push origin master


8.Git的使用
a.Visual Studio使用Git的方法请参见http://m.w2bc.com/article/180738。
b.Git命令行是王道,参见http://www.cnblogs.com/cspku/articles/Git_cmds.html。
c.多个远程库支持参见http://www.aikaiyuan.com/6294.html。
d.多个远程库操作需要使用Visual Studio2015。
f.分支是GIT的一个特色,因为各分支间的代码同步操作都是针对“当前分支”的,所以一定要注意适时用“check out”切换“current branch”。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值