GitHub "can't automatically merge"?

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.


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.


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