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

前端 未结 25 1109
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 05:42

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-n

相关标签:
25条回答
  • 2020-12-04 06:30

    We got this error because we had a comma (,) in the branch name. We deleted the local branch, then re-checked it under a new name without the comma. We were able to merge it successfully.

    0 讨论(0)
  • 2020-12-04 06:35

    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
    
    0 讨论(0)
  • 2020-12-04 06:36

    I had this issue as well. The branch looked like 'username/master' which seemed to confuse git as it looked like a remote address I defined. For me using this

    git merge origin/username/master
    

    worked perfectly fine.

    0 讨论(0)
  • 2020-12-04 06:40

    This may sounds weird, but remember to setup your git email and name:

    git config --global user.email "MY@EMAIL.COM"
    git config --global user.name "FIRST_NAME LAST_NAME"
    
    0 讨论(0)
  • 2020-12-04 06:41

    I had the same problem. I fixed it using the command below:

    git checkout main
    git fetch
    git checkout branch_name
    git fetch
    git checkout main
    git fetch
    git merge branch_name
    
    0 讨论(0)
  • 2020-12-04 06:44

    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.

    0 讨论(0)
提交回复
热议问题