从生产文件夹创建git存储库

从生产文件夹创建git存储库,git,repository,Git,Repository,我有一台带有生产网站的机器,我想在该机器中创建一个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 chec

我有一台带有生产网站的机器,我想在该机器中创建一个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
当post接收挂钩被激活时,它会被触发

有没有关于我可能做错了什么的建议

更新

在第一步中,在生产机器中创建空的.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'.

我宁愿保持回购协议的光秃秃的,然后在后接受挂钩

cd /path/to/non-bare/repo
git --git-dir /path/to/non-bare/repo/.git --work-tree=/path/to/non-bare/repo pull
即:

  • 从裸回购(您可以推动)中提取,然后从第二个非裸回购中提取
  • 而不是试图直接推动裸回购(这很难,如“”中所述)

如果要签出,请不要使用
--bare
。是否有任何方法可以使用checkout命令执行此操作?我宁愿使用它,因为我们所有的其他网站都是这样安装的。遗憾的是,我们的系统管理员不再与我们在一起,我必须自己做这件事。@rfc1484确定:我在y答案中提到的问题建议您(以及)可以看到,这涉及结帐,但仍然使用裸回购。这被认为是世界上最实际的解决办法。