Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Resolving a merge request locally with a protected branch

I am using Gitlab, and I have a conflict on my merge request that I cannot resolve with the online tool. I checkout the target branch and resolve the conflict, then ... Then what ?

  • The branch is protected, so no one is allowed to push on it.
  • No option available on Gitlab to do something like this.

What is supposed to be the correct "way" of doing in those cases ? Are we supposed to create another branch to solve the conflict, then another merge request ? Or is there a commmand line / an alternative I failed to see when searching for a solution, like "push the result of the solving conflict which is not a commit per se" ?

like image 833
Yassine Badache Avatar asked Mar 13 '20 09:03

Yassine Badache


People also ask

Can I commit to protected branch?

After enabling required status checks, all required status checks must pass before collaborators can merge changes into the protected branch. After all required status checks pass, any commits must either be pushed to another branch and then merged or pushed directly to the protected branch.


2 Answers

Are we supposed to create another branch to solve the conflict, then another merge request ?

Yes, I'd suggest doing this.

1) Create a new branch off the destination branch
2) Merge your feature branch in it
3) Solve conflicts, add them, and commit the merge
4) Push that new branch to remote
5) Create a new PR from the new branch to the destination one

like image 156
Romain Valeri Avatar answered Sep 20 '22 23:09

Romain Valeri


The branch is protected, so no one is allowed to push on it.

I assume you mean target branch is protected and my answer is based on that.

To avoid merge conflicts in Gitlab I usually choose one of the 2 options:

  1. Rebase development branch on target branch, solve conflicts during rebase and push force updated branch:
git checkout <development branch>
git rebase <target branch>
# optionally interactive rebase, if I have many commits I like to squash them to avoid solving the same conflicts over and over again
# git rebase -i <target branch>
git push -f
  1. Merge target branch to your development branch locally and solve the conflicts, push it to Gitlab, then you should not have any merge conflicts on your MR.
like image 37
makozaki Avatar answered Sep 20 '22 23:09

makozaki