Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to resolve git's "not something we can merge" error

I just encountered a problem when merging a branch into master in git. First, I got the branch name by running git ls-remote. Let's call that branch "branch-name". I then ran git merge branch-name command and got the following result:

fatal: branch-name - not something we can merge

How do I resolve this error?

like image 232
Brian Avatar asked May 31 '13 17:05

Brian


People also ask

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.

How do I delete a failed merge?

Use git-reset or git merge --abort to cancel a merge that had conflicts. Please note that all the changes will be reset, and this operation cannot be reverted, so make sure to commit or git-stash all your changes before you start a merge.

What is a git merge error?

What is a Git Merge Conflict? A merge conflict is an event that takes place when Git is unable to automatically resolve differences in code between two commits. Git can merge the changes automatically only if the commits are on different lines or branches.


3 Answers

As shown in How does "not something we can merge" arise?, this error can arise from a typo in the branch name because you are trying to pull a branch that doesn't exist.

If that is not the problem (as in my case), it is likely that you don't have a local copy of the branch that you want to merge. Git requires local knowledge of both branches in order to merge those branches. You can resolve this by checking out the branch to merge and then going back to the branch you want to merge into.

git checkout branch-name
git checkout master
git merge branch-name

This should work, but if you receive an error saying

error: pathspec 'remote-name/branch-name' did not match any file(s) known to git.

you need to fetch the remote (probably, but not necessarily, "origin") before checking out the branch:

git fetch remote-name
like image 140
Brian Avatar answered Oct 06 '22 21:10

Brian


It's a silly suggestion, but make sure there is no typo in the branch name!

like image 32
endless Avatar answered Oct 06 '22 20:10

endless


When pulling from a remote upstream, git fetch --all did the trick for me:

git remote add upstream [url to the original repo]
git checkout [branch to be updated]
git fetch --all
git merge upstream/[branch to be updated]

In other cases, I found the "Not something we can merge" error will also happen if the remote (origin, upstream) branch does not exist. This might seem obvious, but you might find yourself doing git merge origin/develop on a repo that only has master.

like image 95
Eneko Alonso Avatar answered Oct 06 '22 20:10

Eneko Alonso