git post-receive not working correctly

我的未来我决定 提交于 2019-11-27 15:02:52

问题


I have the following problem. I have updated the 'post-receive' to cd into a certain directory and then pull the repo in to deploy it like so:

#!/bin/bash
cd /var/www/site
git pull origin master

However whenever I do 'git push origin master' on my local machine I get the following:

Counting objects: 5, done.
Delta compression using up to 2  threads.
(etc..)
remote: fatal: Not a git repository: '.'

Yet when I manually cd to /var/www/site and do git pull origin master it works brilliantly.


回答1:


Use unset GIT_DIR as following

#!/bin/bash
cd /var/www/site || exit
unset GIT_DIR
git pull origin master
exec git-update-server-info

You can see more information about GIT_DIR here. Git Loves the Environment




回答2:


Another option is you can mention the working directory and git directory in the command.

git --work-tree=/home/user/repos/my_app --git-dir=/home/user/repos/my_app/.git <command>

e.g:

git --work-tree=/home/user/repos/my_app --git-dir=/home/user/repos/my_app/.git status


来源:https://stackoverflow.com/questions/9905882/git-post-receive-not-working-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!