问题:如果该工作树不是裸露的,我如何将本地提交推送到我的开发服务器?
我的情况:
- 我在我的开发服务器上设置了 git,这样当我推送本地更改时,它们会被添加到一个分离的工作树中(如此处所述,很像这篇文章)。
- 然后我在开发服务器上运行 git 时遇到了问题(例如,
git status
),因为 git 找不到工作树。 - 我询问了 SO 并得到了我需要
bare = false
在我的配置文件中设置并指定工作树的提示。甜的。
但是现在当我尝试将我的提交推送到开发服务器时,我收到了这个错误:
$ git push origin master
xxxx@xxx.xxx.xxx.xxx's password:
Counting objects: 26, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (18/18), done.
Writing objects: 100% (18/18), 2.56 KiB, done.
Total 18 (delta 8), reused 0 (delta 0)
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'.
To ssh://xxxx@xxx.xxx.xxx.xxx/xxx/xxx/xxxxxx.git
! [remote rejected] master -> master (branch is currently checked out)
error: failed to push some refs to 'ssh://xxxx@xxx.xxx.xxx.xxx/xxx/xxx/xxxxxx.git'
我看到这个其他用户有同样的问题。不幸的是,对他有用的解决方案是bare = true
在他的配置中设置,这将重现我在上面第 3 步中遇到的问题。
错误消息说
您可以将“receive.denyCurrentBranch”配置变量设置为远程:错误:“忽略”或“警告”
就我而言,我可以这样做吗?这对我来说听起来不错,但我对 git 还不够熟悉,还没有意识到当它出现时是个坏主意......
编辑
为了清楚起见,我已经添加了一个 post-receive 钩子,它工作顺利。问题是我似乎必须在bare=true
(并且能够推送到开发服务器)和bare=false
(并且能够在开发服务器上运行 git 命令)之间进行选择。