在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”。

相关文章

文章浏览阅读2.3k次,点赞4次,收藏22次。最近安装了CARLA预...
文章浏览阅读6.3k次,点赞5次,收藏15次。在清华镜像中下载U...
文章浏览阅读5k次。linux环境, python3.7.问题描述: 安装...
文章浏览阅读4.2k次,点赞4次,收藏17次。要安装这个 standa...
文章浏览阅读894次,点赞51次,收藏31次。在安卓使用vscode主...