Home > database >  Resolve conflict in git without merging in main branch
Resolve conflict in git without merging in main branch

Time:11-07

I have a question about resolving conflict in git. I work with feature-branch workflow and github. Sometimes, when I want to merge my branch with the main branch (via a PR), a conflict occurs

To resolve the conflict on my laptop, I have the habit to merge the main on my branch to resolve the conflicts with my editor and then push again the branch. SO, the conflict is reslved and the github can lerge my branch with main Is it a good solution? I ask this question because alla that I found on the net is to merge the branch on main and then push the main branch. But this solution is not suitable when I haven't the permission to ush on the main branch

CodePudding user response:

What you are doing is good. Merge the master to you feature branch, push and it will update your PR correctly.

Even if you have permissions pushing directly to master is a bad practice. Pull requests are there for a reason, so people can review your changes before merging. It's beneficial for the requestor and reviewer both.

The other option is rebase, but it might break your PR because the commit hash changes on rebase.

You can rebase your commit on master using below,

X is the number of commits from HEAD

git rebase --onto master feature~X feature

this will set your feature branch to master version and put the X number of commits that were on feature branch to top of master. This way unlike merge your changes will be on the top of feature branch, instead of somewhere in the middle.

Then you have to force push to remote feature branch and create a PR.

  •  Tags:  
  • git
  • Related