我有一台带有生产网站的机器,我想在该机器上创建一个 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'.