我刚刚遇到了一个问题,合并一个分支到主git。首先,我通过运行git ls-remote来获得分支名称。我们称这个分支为“branch-name”。然后我运行git merge branch-name命令,得到如下结果:

fatal: branch-name - not something we can merge

如何解决此错误?


当前回答

如果您没有使用origin关键字,并且分支不是您自己的分支,也可能遇到此错误。

git checkout <to-branch> 
git merge origin/<from-branch>

其他回答

我必须建议先检查所有的分支机构,或者你要找的分支机构是否可用

Git branch -r

从列表中检查

origin/HEAD -> origin/main
origin/feature/branch_1
origin/feature/branch_2
origin/feature/branch_3
origin/feature/branch_4
origin/feature/your branch

建议从origin本身复制清单,然后git合并origin/feature/branch_2。复制粘贴将删除打印错误。

这可能听起来很奇怪,但请记住设置你的git电子邮件和名称:

git config --global user.email "MY@EMAIL.COM"
git config --global user.name "FIRST_NAME LAST_NAME"

当从远程上游提取时,git fetch——所有这些都为我做了一件事:

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]

在其他情况下,如果远程(起源,上游)分支不存在,我发现“Not something we can merge”错误也会发生。这似乎是显而易见的,但您可能会发现自己在只有master的repo上执行git合并origin/develop。

Git重新设置要合并的分支

我使用这个git命令解决了这个问题,但是rebase只适用于某些情况。

下面的方法每次都对我有效。

git checkout master
git pull
git checkout branch-name-to-be-merged
git pull
git checkout branch-name
git pull
git merge branch-name-to-be-merged