git - 通过 git push 模拟 git pull --rebase

我有一个名为 production 的服务器,其中包含从 master 分支 checkout 并执行的 git 源代码。 此外,我还有一个 development 服务器,其中克隆了我进行代码修改的 git 存储库。
我想同步源代码development -> production
我最初的想法是在 production 服务器上运行 git pull --rebase 以获取最新的提交文件。但是,由于网络限制(防火墙等),production 无法联系 development 但反过来也行得通:development 可以 git pull/push 来自 production.
当我尝试推送时,我收到以下消息:

+ git push origin master
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'.      

我的理解是,为了推送更改,我应该配置 receive.denyCurrentBranch,然后在推送后在生产主分支上执行 git reset --hard。这还将覆盖生产中未提交的更改。
有更安全的方法吗?例如,有时有人可能会 ssh 到生产机器并直接更改那里的代码。我更希望我的命令在这种情况下会失败。另一个例子是生产服务器有一些我不敢覆盖/删除的未跟踪文件。

除了生产服务器上的 git reset --hard 之外,还有其他方法吗?

最佳答案

评论中提到的一些建议:

  1. 推送到 production 上的另一个分支,git pull。 生产 机器上的 BRANCH_NAME
  2. production 机器上设置额外的裸仓库。由于 git 是分布式的,服务器可以在任何机器上,对于我的网络限制情况,将它放在 production 上很简单。

我最终实现了#1。

https://stackoverflow.com/questions/63801514/

相关文章:

python - 将 Python2 文件派生类移植到 Python 3

javascript - 监听关闭事件 react 导航

c# - 无法复制文件,找不到部分路径

c# - 列出目录中的文件夹,其 id 不是 Google Drive API v3 和 C# 中的

amazon-web-services - 如何更改 CodePipeline 工件行为? (如果可

python - grpc python 测量响应时间

ios - dyld : Symbol not found: _OBJC_CLASS_$_Reach

angular - Jasmine Angular : How to write unit test

java - Apache Storm 本地集群 "Unable to canonicalize a

javascript - 汇总、Svelte、SCSS : how to build differe