我有一台带生产网站的机器,我想在该机器上创建一个git存储库,以便使用git管理网站。
所以我做的第一件事就是在生产机器中创建一个空的.git存储库:
mkdir repos
cd repos
mkdir production.git
cd production.git
git init --bare
在hooks / post-receive下的这个存储库中,我添加了以下行:
#!/bin/sh
GIT_WORK_TREE=/var/www/production_website git checkout -f
然后我将生产网站的文件夹下载到我的本地机器上并启动了git:
cd production_website
git init
之后我做了第一次提交:
git add .
git commit -m "first commit"
最后我添加了远程存储库并进行了第一次推送:
git remote add origin ssh://myuser@productionmachine.com/repos/production.git
git push origin master
但是当我进行推送时,它会给我以下错误消息:
remote: fatal: This operation must be run in a work tree
当激活后接收挂钩时触发它。
有关我可能做错的任何建议吗?
更新:
在第一步中,当在生产机器中创建一个空的.git存储库时,如果我使用git init
而不是git init --bare
,我在推送时会收到此错误消息:
remote: error: refusing to update checked out branch: refs/heads/master
remote: error: By default, updating the current branch in a non-bare repository
remote: error: is denied, because it will make the index and work tree inconsistent
remote: error: with what you pushed, and will require 'git reset --hard' to match
remote: error: the work tree to HEAD.
remote: error:
remote: error: You can set 'receive.denyCurrentBranch' configuration variable to
remote: error: 'ignore' or 'warn' in the remote repository to allow pushing into
remote: error: its current branch; however, this is not recommended unless you
remote: error: arranged to update its work tree to match what you pushed in some
remote: error: other way.
remote: error:
remote: error: To squelch this message and still keep the default behaviour, set
remote: error: 'receive.denyCurrentBranch' configuration variable to 'refuse'.
答案 0 :(得分:2)
我宁愿保持回购裸,然后在收货后挂钩
cd /path/to/non-bare/repo
git --git-dir /path/to/non-bare/repo/.git --work-tree=/path/to/non-bare/repo pull
那是: