Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"This pull request contains merge conflicts that must be resolved."

Tags:

git

github

I'm getting that error with a PR, but when I git status it says nothing to commit, working directory clean.

That's on the branch with the PR.

On branch pr12 nothing to commit, working directory clean 
like image 502
Nathan Avatar asked Oct 07 '14 17:10

Nathan


People also ask

How do I see a merge conflict in a pull request?

Pull the most recent version of the repository from Bitbucket. Checkout the source branch. Pull the destination branch into the source branch. At this point, pulling the destination will try to merge it with the source and reveal all the conflicts.

How do I resolve a merge conflict in bitbucket pull request?

In short, you resolve the merge conflict locally by checking out your feature branch and then merging the remote develop into it. You will have to resolve the conflicts, commit the merged code and push to the remote feature branch.


2 Answers

git status tells you about the state of your working directory tree and your index (where staged changes live) relative to the latest commit on the current branch. The output you're seeing means that the files on your disk exactly match the latest commit on your branch. That is, there's "nothing to commit".

The message from GitHub is not about committing, but about merging. GitHub would like to offer you a one-click method to merge this branch into your master branch, but it can't, because that merge results in conflicts. Since GitHub doesn't have a way to help you resolve conflicts though the website, it asks you to resolve them on your own machine.

The best way to deal with this situation is to merge the current master branch into your topic branch locally and then push the result to GitHub. To do that, do the following:

$ git checkout pr12  # If you're not already on pr12 $ git fetch origin $ git merge origin/master 

(I'm assuming that the GitHub remote is called origin. It typically is, and you probably know if it isn't.)

First we make sure we're on the right branch. Then we make sure we have the latest code from the master branch on the GitHub repo. Then we merge that code into our pr12 branch.

Remember: git fetch origin updates our local origin/master to be the same as GitHub's master, but it doesn't touch the local branch called simply master. We'd have to checkout our master branch to make changes to it. Instead, we just update our idea of what's on GitHub (origin/master) and merge that into our pr12.

When you run the merge command, you'll see conflicts. Those represent decisions that git (and GitHub) couldn't make automatically. Edit those files so they're the way you want them to end up. Then:

$ git add each/file.txt that/had/conflicts.conf $ git commit   # Your editor will open with a pre-filled                # commit message. Just save and close the file. $ git push origin pr12 

That is, we add the versions of the files that we fixed, then finish the merge commit we started with git merge. Lastly, we push the branch with the new merge commit up to GitHub.

Since we've resolved the conflicts, this branch should be trivial to merge the other way, into master. GitHub will notice that, and give you a green "Merge" button.

like image 66
Peeja Avatar answered Sep 25 '22 14:09

Peeja


When I encountered this message, it was because my fork of a particular repo was behind the original. In my particular case the repo I'd forked is pydata/pandas.

I had to configure a remote for my fork by doing:

> git remote add upstream [email protected]:original_user/original_repo.git > git remote -v origin  [email protected]:some_user/pandas.git (fetch) origin  [email protected]:some_user/pandas.git (push) upstream    [email protected]:pydata/pandas.git (fetch) upstream    [email protected]:pydata/pandas.git (push) 

(Note: git remote add upstream is a git's way of saying "Add a remote called "upstream". The name can be anything.)

Then I fetched the latest commits from the original repo with:

> git fetch upstream > git checkout master # Just in case you're not already on master > git merge upstream/master 

and finally push the merged repo back to github:

> git push 
like image 43
LondonRob Avatar answered Sep 21 '22 14:09

LondonRob