Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can I solve a conflict in a pull request?

ramo102 June 10, 2016

Suppose I have two branches, master and release/2.0, and I want to merge the release branch into master.

I do a pull request to merge release/2.0 to master, but, after the pull request has been done, I discover that there is a conflict (for example, application's version within the main POM).

How can I solve the conflict? Is the previous one (direct pull request in BitBucket) the right approach, or I have to perform the merge in my local environment and then make the pull request? In this case, which are the steps to perform?

Thanks in advance.

9 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

50 votes
Answer accepted
Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 10, 2016

You have two options to resolve the conflict:

1) Resolve them without a pull request.

To do this, you would checkout the master branch, and then pull in the release branch. This is effectively the solution that Bitbucket Server give you when you ask for more information on how to solve the conflict.

$ git checkout master
$ git pull origin release/2

<resolve merge conflicts and commit>
$ git push

2) Resolve them with a pull request

To do this, you would create a branch off the tip of master, pull in the release branch and create a pull request from that branch to master. This is the best option if you don't have permission to push directly to master.

$ git checkout master
$ git checkout -b resolve-conflicts-branch
$ git pull origin release/2

<resolve merge conflicts and commit>
$ git push -u origin resolve-conflicts-branch
<create pull request>

 

Note: Once you have resolve the conflicts through either of these methods, your old pull request from release/2 to master will be closed automatically since there will no longer be any diff.

ramo102 June 13, 2016

The second solution is fine for me.

Like # people like this
Stefan Wendelmann August 28, 2018

1) Works for me, before i push i had to commit

Like # people like this
Carol Skelly February 11, 2019

But solution 1 pushes back to master and closes the pull request which we don't want if the PR is still pending review/approval, correct?

Like Ron _3DIT_ likes this
Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 11, 2019

Correct, however the pull request that has been automatically opened doesn't have any reviewers by default. So it's totally up to your team how you would like to handle them. If you want the merge conflict resolution to be reviewed, then you should go with option 2 where you open a new pull request on a branch with a different name (but the same head commit). Once that pull request has been reviewed and merged, the initial pull request will be automatically closed so you don't have to worry about it.

If your team doesn't feel like it is necessary to have reviewers on all pull requests, or doesn't feel like it is necessary to review merge conflict resolution changes, then they can just go for option 1, which is a little bit less convoluted.

Like # people like this
Mario Heleno Santos April 26, 2019

Hi @Kristy is it possible to add in answers the process for Mercurial repos?

I'm know it not widely used as git but it is what we have here.

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 28, 2019

Hi Mario,

This question is specifically about the automerge feature of Bitbucket Server. Bitbucket Server does not support Mercurial, which is why the answer is git-specific.

If you have a question about merge conflicts in Mercurial, I suggest that you create a new post for it and tag it as "Bitbucket" (not "Bitbucket Server") so that you are able to give all the details of your question.

 

Regards,

Kristy

Like Mario Heleno Santos likes this
Mario Heleno Santos April 29, 2019

Ok. Thanks

Muhammad Tahir May 13, 2019

Steps DONE

git pull

git checkout <feature_branch>

git pull origin <destination_branch>
git add <filename>
git commit -m'commit message'

When I tried to run ->

git push origin <feature_branch>

I got the following error 

error: src refspec <BRANCH-NAME> does not match any.

 

error: failed to push some refs to 'PRIVATE_URL'


Can someone tell me reason ?

Nitesh Gour September 5, 2019

Thanks!

Irshadkhan Perception December 6, 2020

Thanks Kristy,

solution 1 works for me.

Manjunatha NS April 16, 2021

hi

i tried the solution 2) Resolve them with a pull request but Conflict got resolved but my automatic merge pull request will not closed, can you please advise 

12 votes
Tim Crall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 10, 2016

perform the merge in reverse locally, merging master into release/2

git checkout release/2
git merge master

then manually resolve any conflicts, commit and push

git commit
git push

Your pull request should automatically update itself to the new commit and there are no longer any conflicts (because you just resolved them all)

BETTER YET

You could also use a rebase instead of a merge.  This gives a cleaner look to your history, at the cost of a little bit of historical accuracy.  Many people think that's a good deal.

git checkout release/2
git rebase master
&lt;resolve conflicts manually&gt;
git push

As before, your Pull Request should now be mergeable

 

 

 

ramo102 June 10, 2016

Hi @Tim Crall,

I need to merge the release branch into master; does your solution do the opposite?

Tim Crall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 10, 2016

It does the opposite locally as a means of resolving the conflicts between them.  It then uses the Pull Request to do the actual merge in the correct direction.

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 10, 2016

When you push onto release/2 you are have effectively merged master into release/2. This is not what you want to do if you would like your release branch to not contain all the commits that exist on master.

Tim Crall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 13, 2016

True.  I was kind of assuming you'd be deleting the release branch after merging it into master.  

In GitFlow branching strategy, a release branch should usually be deleted (or at least abandoned) after the release was finalized, which is when you would merge it back into master.

 

BarriePfeifer December 10, 2018

Digging up old threads....  Is there a way to config Bitbucket to only merge if the source branch is already up to date with the destination?

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 10, 2018

@BarriePfeifer, yes there is.

You can configure the merge strategies to only allow fast-forwards.

However, depending on your configuration this might make it difficult to make sure your branch is always ahead of the destination and also give enough time for a green build (because rebasing will change the commit hashes, and hence the builds). Of course if you don't have frequent changes to the destination branch and your pull request builds are fast then it will probably be ok.

Depending on your use case, you may also be interested in the Auto-unapprove plugin that will reset the reviewers' approvals when there are meaningful changes on the destination branch. If this is coupled with a merge check that ensures that the reviewers have approved then it can also block the merge.

Hope this helps,

Kristy

Ron _3DIT_ March 7, 2019

Instead of doing

git merge master

you might want to consider fetching the remote branch first or simply do

git merge origin/master

Your PR will be updated accordingly (commit and push) and all merge conflicts should be resolved.

3 votes
M S September 30, 2018

Why is there no online web GUI app that makes the merging easier?

I don't want to deal with command line when needing to resolving conflicts. GitHub already has an online tool that does that.

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 1, 2018

There is a feature request for this you can vote on and watch: https://jira.atlassian.com/browse/BSERV-4617

1 vote
Mohammed Davoodi
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 16, 2017

We've developed a plugin, Power Editor for Bitbucket, that allows you to resolve conflicts on a pull request in the UI. You won't need to go through any of the git commands anymore smile (even though we highly recommend you learn them, they can be quite useful). You can check out out here.

It also supports:

  • Adding, renaming and deleting files
  • Editor extensions like preview, view diff and tab and space controls.
  • Editing functionality in pull requests to quickly fix typos in files.
  • Full support for hooks.
0 votes
Johnson Clarke July 28, 2020

Using this code on homepage of my site.

$ git checkout master
$ git pull origin release/2

<resolve merge conflicts and commit>
$ git push
0 votes
Christiana Parker September 27, 2019

When you have merge conflicts, you can't click the Merge button from the pull request to merge. To resolve these conflicts, you pull the changes to your local repository and fix them there. beside this if you've Forgot Roadrunner Password so don't worry about it just check the link to make every issue solve by experts.

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 29, 2019

In this case, I believe the question was about a pull request from a `release/` branch. In this case, you wouldn't want to pull the target branch into the source branch because the `release/` branches should always be behind the target branch

0 votes
Kidane Yosief June 14, 2019

you would need to resolve the conflict in your branch first.

 

git checkout yourBranch

git merge origin/master

resolve your conflict

git add . && git commit -m "conflict resolve" && git push

This way your pull request will look fine. 

it can be reviewed and merged perfectly ... 

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 14, 2019

This would usually work for most branches, however the example that has been posted is for a release branch merging into master. Most of the time, there would be branch permissions set up to stop you from pushing directly to release branches so this approach may not work in those cases where you do not have permission to push to the branch.

0 votes
David Latty February 6, 2019

The problem is if any of the merged code is postponed or abandoned (e.g. to requirement needs) your master ends up with code - and this is bad as that code may likely be issued. It may also not have been the last commit. What happens then?

0 votes
Casey Wise September 13, 2018

I resolve locally, w/ a non-fast forward merge from the target branch into the source branch.  A word about non-fast forward merges, they create an easily rescinded commit should you require a rollback.

1. Checkout to master, get latest, checkout to your release/2.0 and non-fast forward merge master in to it:

git checkout master && git pull && git checkout release/2.0 && git merge --no-ff master

2. Your output will indicate which files are conflicting.  Iron out those conflicts.

3. Commit the conflict resolution, push your release branch back up for a clean pull request.

git commit -am "resolve merge conflict" && git push

 

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 13, 2018

@Casey Wise, maybe I'm misunderstanding your comment but it seems to me that this will result in all the changes from master being on the release branch.

If you then want to make a bugfix to that release branch, you may not get what you expect because it will contain all the changes from master too - which may be API breaking, contain extra features etc and is against the rules of SemVer.

Casey Wise September 14, 2018

@Kristy If there's broken or unnecessary code on master you don't want cleanly merging w/ your release/feature/hotfix, someone owes the office donuts and/or bagels!

git blame

 

Kristy
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
September 16, 2018

Its not that there is broken code on master, but that the release branches should be strictly behind master. Master will contain the newest features, which you might not want merged into old release branches for the sake of compatibility.

Like # people like this
Casey Wise September 17, 2018

Perhaps!

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events