Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GitHub "can't automatically merge"?

Tags:

git

merge

github

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.

like image 425
user2568374 Avatar asked Aug 12 '15 18:08

user2568374


People also ask

Why GitHub Cannot automatically merge?

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).

How do you fix can't automatically merge don't worry you can still create the pull request?

Checkout via command line If you cannot merge a pull request automatically here, you have the option of checking it out via command line to resolve conflicts and perform a manual merge. Step 1: From your project repository, check out a new branch and test the changes. Step 2: Merge the changes and update on origin.

Why git merge not working already up to date?

The message “Already up-to-date” means that all the changes from the branch you're trying to merge have already been merged to the branch you're currently on. More specifically it means that the branch you're trying to merge is a parent of your current branch.


2 Answers

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.

like image 170
aaa bbb Avatar answered Oct 06 '22 14:10

aaa bbb


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.

like image 29
Thomas Stringer Avatar answered Oct 06 '22 14:10

Thomas Stringer