1

Sometimes, in my team, a developer will forget to pull from master before merging. We don’t really do code reviews at this point, which brings up my question:

Is there a way to enforce that before merging Branch A into Branch B, Branch A has to contain the last commit of Branch B?

EDITS

I’m looking for an automated code review process where the only requirement would be to contain the last commit of the target branch.

I had a look at branch protection. But it unfortunately doesn’t seem to help with my specific case.

Jalil Compaoré
  • 394
  • 3
  • 12
  • Possible duplicate of [Git: auto pull from repository?](https://stackoverflow.com/questions/9978400/git-auto-pull-from-repository) – R4444 Sep 14 '19 at 18:16
  • I think what you're looking for is [branch protection](https://stackoverflow.com/questions/38864405/how-to-restrict-access-to-master-branch-on-git) – Skam Sep 14 '19 at 18:17
  • @R4444 I’m not really looking for an auto pull. I wouldn’t want the developer in branch A to be disturbed but periodic pulls. – Jalil Compaoré Sep 14 '19 at 18:35
  • @Skam I had a look at branch protection, but it doesn’t seem to offer what I’m looking for. https://help.github.com/en/articles/about-protected-branches#branch-protection-settings – Jalil Compaoré Sep 14 '19 at 18:37

2 Answers2

0

After review is finished instead of pressing buttons on UI you can push to master manually either from command line or from IDE. If someone's pushed to master already you'll get an error, so you'll have to incorporate origin/master commits into your local history.

GitHub has "Allow merge commits" in the settings and if you uncheck it - your team won't be able to create those automated merges. But they'll still be able to either squash or rebase (at leat 1 option must stay checked) which means they still can push to master w/o pulling changes to feature branch first. So you'll have to talk to them and simply ask not to use UI.

Stanislav Bashkyrtsev
  • 14,470
  • 7
  • 42
  • 45
0

If I'm not mistaken, a required status check is exactly what you want. Suppose master is the branch you want to protect. You can set it so you can't push to master directly. if a branch feature/foo is out of date but I want to merge it in, then I can enforce that my branch must be updated with master. As a heads up, you must be an administration on the repository to setup required status checks for a repository.

Skam
  • 7,298
  • 4
  • 22
  • 31