简体   繁体   English

将功能分支推送到远程存储库以与不同步的 master 合并

[英]Pushing feature branch to remote repository to merge with not in sync master

In the company I work for, the developer is pushing the local feature branch after changes locally committed, to the remote repository.在我工作的公司中,开发人员在本地提交更改后将本地功能分支推送到远程存储库。 Then after the code review, the feature branch is merged into master (the remote master).然后经过代码审查,将特性分支合并到master(远程master)中。

My question is:我的问题是:

What if the local master and the remote master not in sync?如果本地master和远程master不同步怎么办? Then the branch is merged into a completely different project?然后分支合并成一个完全不同的项目? For example, I git cloned master 2 weeks ago + branched from it to a new feature branch, but in these two weeks, changes have been made to the master.比如我 git cloned master 2 周前 + 从它分支到一个新的特性分支,但是这两个星期,对 master 做了改动。 So my worry is that my feature branch will be merged into totally different master branch!所以我担心我的功能分支会被合并到完全不同的主分支! Without me testing it first.没有我先测试。

Question: isn't a smarter workflow would be to before pushing the feature branch to remote repository and pull request to first:问题:在将功能分支推送到远程存储库并首先拉取请求之前,不是一个更智能的工作流程:

git checkout master
git pull
git checkout my-feature-branch
git merge master (now i know my branch is in sync with master. Resolve conflicts locally)

and only then:只有这样:

git checkout my-feature-branch
git push origin my-feature-branch?

The flow I've seen being employed in several companies (successfully) is as follows:我在几家公司(成功)中看到的流程如下:

  1. Merge the feature branch to the main development branch:将功能分支合并到主开发分支:
    • Checkout an updated version of the development branch.签出开发分支的更新版本。
    • Merge the development branch into the feature branch and resolve all possible conflicts.将开发分支合并到功能分支并解决所有可能的冲突。
    • Commit/Push the feature branch in its 'Ready to be merged to the development branch' state.提交/推送处于“准备合并到开发分支”状态的功能分支。
    • Merge the feature branch into the development branch (and now the feature branch can be removed).将功能分支合并到开发分支中(现在可以删除功能分支)。
    • Run CI/CD tests on the development branch in order to verify that the merge is valid.在开发分支上运行 CI/CD 测试以验证合并是否有效。
  2. Merge the main development branch into the master branch (should be done with care and all other developers should be notified that the development branch is being merged into the master):将主开发分支合并到主分支(应该小心完成,并且应该通知所有其他开发人员开发分支正在合并到主分支):
    • Checkout an updated version of the master branch.签出主分支的更新版本。
    • Merge the master branch into the development branch (should not be an issue since the development branch should contain everything in the master branch).将 master 分支合并到 development 分支中(应该不是问题,因为 development 分支应该包含 master 分支中的所有内容)。
    • Commit/Push the development branch in its merged state.提交/推送处于合并状态的开发分支。
    • Merge the development branch into the master branch (and decide on whether or not the commits should be squashed).将开发分支合并到主分支(并决定是否应该压缩提交)。
    • Make sure the master is stable running all possible tests on the master branch.确保 master 是稳定的,在 master 分支上运行所有可能的测试。
    • Create a tag of the merge commit - merging from development to branch is generally done as a prelude to a version release.创建合并提交的标签 - 从开发到分支的合并通常作为版本发布的前奏。

References:参考:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM