84

Sometimes when i try to merge the head fork into my base fork, or my base fork into the head fork, I get the following message on GitHub:

"Can’t automatically merge. Don’t worry, you can still create the pull request."

How do I view the conflicts, if there are any for this?

I have read about 10 different examples with various commands but I can't tell what the names in the examples apply to in my situation as different names for bases, forks, branches, etc, exist.

After all of this, I can't believe there isn't a command you can type to see the conflicts, edit the conflicts and go on with merging. If there is, I haven't found it yet.

5 Answers 5

73

Let's say there is your-branch and the master branch. You want to merge changes from your-branch into the master for others to see them, but someone else did conflicting changes to the master (e.g. merging their PR) in the meantime. It is often useful to merge master into your-branch (i.e. do the merge the other way round) before creating the PR.

In the command line, you can:

git checkout master
git pull
git checkout your-branch
git merge master

Now you can see the list of conflicts. Follow the messages you get from git to resolve the conflicts. You can use your favorite tools, so it is way easier. Finally, you commit&push. When you re-create the PR, there should be no conflicts.

4
  • 3
    Sticking with these same example branches, you could shorten the amount of commands that you need for this by just checking out your-branch, and then doing: git pull origin master Commented Aug 26, 2019 at 22:37
  • 2
    THANKS YOU SAVE MY MIND
    – Oliver D
    Commented Mar 24, 2020 at 18:09
  • Many thanks, I took a less optimal route to solve same problem but thanks to your answer, this is definitely the best way. Wish I could bookmark helpful answers on SO
    – mikaelovi
    Commented Nov 8, 2021 at 10:33
  • Happened to me because my local main branch was not up-to-date with origin git co main && git pull fixed && git co your-branch && git push fixed it
    – eddy147
    Commented Apr 26, 2022 at 10:43
46

That means that your pull request can't be merged into the upstream without the upstream owner(s) having to resolve merge conflicts.

The resolution here would be for you to do a fetch from the upstream and then resolve the merge conflicts from the upstream. At this point, if you theoretically resolve the conflicts from the upstream and then create your pull request, upstream would be able to automatically merge in your pull request without having any conflicts (provided there were no commits on the upstream between you locally resolving the upstream merge conflicts and merging into your local/fork, and then creating the pull request).

Let's use GitHub as an example here for remote repo store.

OriginalAccount\repo1 - say this is the original repository (we will refer to this as "upstream")

YourAccount\repo1 - this would be your fork of the repository (this is typically the "origin" remote)

repo1 local - this is your local copy of the repository.

When you create a pull request from YourAccount\repo1 to OriginalAccount\repo1 (virtually from origin to upstream), seeing the message that you can't merge automatically means that OriginalAccount\repo1 has commits that YourAccount\repo1 doesn't have (commits that were most likely pushed after you forked).

The solution here would be to fetch from upstream to your local repository (from OriginalAccount\repo1 to your local repo) and resolve any merge conflicts locally. Then push your commits to YourAccount\repo1. At this point, you should be able to create your pull request that should be able to be automatically merged into OriginalAccount\repo1.

Note: Even though most Git services won't prevent you from continuing on with a pull request that requires the upstream contributors to resolve merge conflicts, it is good practice and good etiquette to ensure that your pull request merges with no conflict. Think about it like this, you should be doing the merge conflict resolution work, instead of having the upstream contributors doing that work from your contribution.

11
  • 6
    I don't even know what this means "resolve the conflicts from the upstream and then create your pull request" Commented Aug 12, 2015 at 19:05
  • @user2568374 I just edited in an illustrative example. Hopefully that clears up any confusion. Commented Aug 12, 2015 at 19:07
  • 2
    Lost. Can this be done with Github? I tried dragging head fork to left merge square and my branch to right merge square and clicking merge branches and sync but this still does not fix the problem. Commented Aug 12, 2015 at 19:11
  • 2
    Doesn't work, I get the concepts but have no idea how to accomplish this Commented Aug 12, 2015 at 19:13
  • 1
    @ThomasStringer: It would be useful to have some example commands and/or screenshots to illustrate your example. It'd be nice to see what "fetching from upstream" and "resolve any merge conflicts locally" would look like.
    – jvriesem
    Commented Feb 25, 2019 at 20:53
4

The easy way to do this is to use Github this way:

  • In Github select branches tab, click merge view button, drag your head fork to the left box, drag your base fork to the right box.
  • Click Merge Branches button.
  • Select changes tab.
  • Select each file that has conflicts. see '<<<<<<<' Edit files in external viewer to keep headfork code and add yours to it.
  • Click Save on file(s).
  • Click Commit to button.
  • Click sync.
  • Go to Git website and try merging your base fork to head fork again.

It should no longer show the original message

1
  • 3
    since I added this , Github has changed their interface. The concept should be the same though. Will update with new solution for new interface when I get this problem again Commented Aug 18, 2015 at 15:58
-1

You get conflicts when your code being merged into the repo will conflict with the code already there. If your pull request is accepted, it will be up to the repo manager to resolve them.

0
-2

Nice answer from : Clean up a fork and restart it from the upstream

The simplest solution would be (using 'upstream' as the remote name referencing the original repo forked):

git remote add upstream /url/to/original/repo
git fetch upstream
git checkout master
git reset --hard upstream/master  
git push origin master --force 

Not the answer you're looking for? Browse other questions tagged or ask your own question.