简体   繁体   中英

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

My question is:

What if the local master and the remote master not in sync? 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. 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.
  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).
    • 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.
    • Create a tag of the merge commit - merging from development to branch is generally done as a prelude to a version release.

References:

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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