服务器上搭建git仓库与钩子hook的配置
2016-12-19 23:07
821 查看
服务器上的git目录下文件配置
本服务器是基于阿里云上的服务器,服务器上的web服务在/wwwroot/www目录下ssh root/用户名@服务器地址,进入服务器 cd /home/git/ #进入git目录 git init --bare huang.git #初始化一个git仓库
需要先在服务器上添加个Git用户组,并在git用户组里添加个git用户,后面的操作都是使用git这个用户身份操作的。因为我是root权限登录的,所以是root权限,这处必须要修改的。
chown -R git:git huang.git/
此时,git目录下的huang.git文件夹git用户组修改完毕,接下来是修改hook,此处不详述钩子的作用,这里只说明如何用,详细可以自己去查询了解。
钩子hook
进入刚创建的huang.git文件夹里的hooks文件夹中,里面有post-receive和post-update这两个文件(如果没有的话需要自己新建)下面是配置好的post-receive里的文件内容:
#!/bin/sh # # An example hook script for the "post-receive" event. # # The "post-receive" script is run after receive-pack has accepted a pack # and the repository has been updated. It is passed arguments in through # stdin in the form # <oldrev> <newrev> <refname> # For example: # aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master # # see contrib/hooks/ for a sample, or uncomment the next line and # rename the file to "post-receive". #. /usr/share/git-core/contrib/hooks/post-receive-email # cd /wwwroot/www/你的项目文件名(这里为huang) cd /wwwroot/www/huang env -i git pull
下面是配置好的post-update里的文件内容:
#!/bin/sh # # An example hook script for the "post-receive" event. # # The "post-receive" script is run after receive-pack has accepted a pack # and the repository has been updated. It is passed arguments in through # stdin in the form # <oldrev> <newrev> <refname> # For example: # aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master # # see contrib/hooks/ for a sample, or uncomment the next line and # rename the file to "post-receive". #. /usr/share/git-core/contrib/hooks/post-receive-email cd /wwwroot/www/huang env -i git pull
web目录下文件配置
git目录下的文件配置完毕,接下来进入web目录/wwwroot/www。将git目录下刚创建的空仓库的内容clone过来,命令如下:ls -la
chown -R git:git huang/
本地clone远程项目
到此,服务器上的仓库文件配置完毕。在本地clone远程服务器上的空仓库,命令如下:git clone git@服务器地址:huang.git
进入该项目文件夹,添加代码文件
git add . git commit -m "1" git push
这个时候git目录下的代码会得到更新,同时由于钩子的作用,web目录(/wwwroot/www)下的代码也得到了同步更新。如果web目录下的代码没有更新,可能是版本产生冲突了,可以在web目录下的项目文件夹(/wwwroot/www/huang)下git pull一下,这样代码就可以正常维护了。
注意,出现如下问题时:
remote: error: insufficient permission for adding an object to repository database ./objects remote: fatal: failed to write object error: unpack failed: unpack-objects abnormal exit
客户端机器对服务器git代码仓库的写权限出了问题。改变代码仓库下,所有文件的访问权限,同组可写,确认严格按照上面的指令执行。chown -R *
相关文章推荐
- CentOS7——gitlab本地git仓库搭建 以及web hook配置
- 搭建git服务器及配置gitosis管理用户权限
- 【学习笔记】ubuntu12.04安装与配置gitolite搭建git服务器
- Linux git服务器搭建 配置IDEA git
- 在linux(CentOS)上搭建git服务器和配置gitolite权限管理
- 一步一步搭建git私有仓库服务器记录
- linux搭建配置以及恢复git服务器
- 自己在本地搭建git版本仓库服务器
- 在服务器上搭建自己的Git仓库(摘录整合)
- 【转】linux(Ubuntu)配置svn仓库,搭建svn服务器
- git仓库的建立与git服务器的搭建
- 在 Ubuntu 上搭建 git 仓库服务器 gitolite
- Github初体验(仓库搭建和git配置入门)
- 在服务器上配置Git仓库
- ubuntu 服务器搭建,bugzilla,git安装配置
- 4步 搭建svn服务器(配置多仓库)
- 搭建Git远程仓库(也就是Git服务器,不用再连Github了)
- 在linux(CentOS)上搭建git服务器和配置gitolite权限管理
- git 服务器搭建,在自己服务器上搭建私有仓库
- Git+TortoiseGit+COPSSH搭建GIT服务器及配置管理