Git部署,也可以从服务器提交更改

时间:2013-12-20 19:21:18

标签: git deployment

我在平面文件CMS上有一个网站,我想通过Git部署。我希望能够从我的本地计算机上工作并推送到实时服务器,但我还需要能够通过CMS的Web管理面板编写新内容,并将这些内容返回到我的计算机,进入我的开发环境

这样做的最佳方法是什么?我试图在我的机器和服务器上简单地使用repo,并将服务器设置为我本地仓库的远程服务器。当我尝试将更改推送到服务器时,我收到错误。

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'.

我总是可以更改遥控器的配置以允许这样做,但我觉得可能有更好的解决方案,因为默认情况下不允许这样做。通过Git实现这一目标的最佳方法是什么?理想情况下,通过管理面板进行的更改将自动提交,但这可能要求太多。

2 个答案:

答案 0 :(得分:2)

您需要3个存储库才能工作:

  1. 裸存储库,它将成为其他两个
  2. 的远程存储库
  3. 一个常规的本地仓库,您可以在这里进行工作并从远程推送/拉动
  4. 作为您的部署站点的服务器上的常规仓库,从远程升级到升级,并在您从cms进行更改时推送
  5. 您可以从任何现有的回购中创建一个裸仓库,如下所示:

    git clone --bare source destination
    

    <强>更新

    此博客文章解释了一种有趣的方法,其中部署目录不是Git存储库:

    http://mattbanks.me/wordpress-deployments-with-git/

    虽然工作树本身不是Git存储库,但你仍然可以像这样运行Git命令:

    GIT_DIR=/path/to/bare.git
    GIT_WORK_TREE=/path/to/work/tree
    git status
    

    我个人使用更复杂的方法,我在部署中有两个站点:mysite.com和dev.mysite.com所以我的post-receive挂钩需要更多逻辑来知道要升级哪个部署,具体取决于分支名称I推送到:

    http://www.janosgyerik.com/deploying-new-releases-using-git-and-the-post-receive-hook/

答案 1 :(得分:0)

如果您使用服务器的SSH密钥到您的git repo,您​​应该能够从服务器提交/推送,这与deploy key方法不同。但不推荐这样做,因为您可能会因创建冲突而遇到麻烦。因为解决服务器上的冲突可能是一项繁忙的任务。