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

fatal: branch-name - not something we can merge

如何解决此错误?


当前回答

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

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

其他回答

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

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

我今天有这个问题,当我将另一个分支合并到我的直接从主后,我必须先签出并拉出我合并的分支,然后我才能成功地将这个分支合并到我的分支中。

git checkout branch-to-merge
git pull
git checkout my-branch-name
git merge branch-to-merge

在我看来,我错过了映射我的本地分支与远程回购。我做了下面的工作,它工作得很好。

git checkout master
git remote add origin https://github.com/yourrepo/project.git
git push -u origin master
git pull
git merge myBranch1FromMain

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

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

我们得到这个错误是因为我们在分支名称中有一个逗号(,)。我们删除了本地分支,然后在不带逗号的新名称下重新检查它。我们成功地合并了。