Home > Software engineering >  GIT branching strategy with 2 branches (master, task) - how to prevent code loss in master branch?
GIT branching strategy with 2 branches (master, task) - how to prevent code loss in master branch?

Time:11-24

I am reading about GIT branching strategy that involves master, develop, hotfix, release, feature.

We are 5 developers working on a python website. Following is branching strategy I want to use on GitHub.

  1. Production code is in the master branch.
  2. I create a Task branch off the master branch.
  3. I work on the Task branch, and before pushing the code to git I switch to master and pull the code, switch to Task and merge with master. This is so that my code is in sync with remote master
  4. Push code
  5. Raise PR from Task branch into master branch.

What happens if master has got additional code that I am missing in my Task branch and I forget to run step 3?

CodePudding user response:

You won't lose code. If your Task branch is pushed without being synced to master first, GitHub will tell you if there are any conflicts.

In case of conflicts, you will get this message on the PR:


enter image description here


Then you can pull master locally, fix the conflicts and push back the changes to Task.

If there are no conflicting files, you can merge without updating your Task branch, even if master is ahead.

CodePudding user response:

If you're using GitHub, you can add a Branch Protection Rule that requires branches to be up-to-date with the master branch before they are allowed to be merged in a Pull Request:

GitHub's 'require branches to be up to date before merging' protection rule

The branch must be up to date with the base branch before merging.

See the GitHub Branch Protection rule documentation here.

  • Related