我从Bitbucket或Github迁移了我的回购。我认为这无关紧要,但这是唯一不同的地方。有一段时间,我设置了两个遥控器:

origin: bitbucket
github: github

然后我删除了这两个,并指向github的起源:

git remote remove origin
git remote remove github
git remote add origin https://github....

开发部门测试推送:

git push origin develop

一切都是最新的,很好。

像往常一样为一些工作创建一个新分支:

git checkout -b Feature/Name

更新一两个文件。尝试推送到远程:

git push origin Feature/Name

这导致了错误:

致命:特征/名称不能解析到分支

在网上搜索这个问题,找到一些关于确保HEAD是正确的,其他关于确保我的分支名称大小写是正确的(尽管,此时远程上还不存在分支)。无法解决。

执行如下命令:

git push --all -u

这让我的功能/名称分支到github,但仍然看到相同的行为之前:

git push origin develop
git push origin Feature/Name

第一个可以工作,而第二个抛出相同的错误。为什么?


当前回答

尝试这个错误:(feature/test是本地分支名称)

Git分支——set-upstream-to=origin/feature/test feature/test

其他回答

在遇到类似的问题后,我决定张贴对我有用的东西。

我尝试用命令将新的分支推到远程存储库:

git push --set-upstream origin <branch name copied from Git console after navigating to the repository location>

并得到以下状态信息:

warning: redirecting to <myRepositoryAdress>

fatal: <branch> cannot be resolved to branch

首先,我们迁移了Git,我认为这可能是问题所在,但事实并非如此。

实际的问题是:

而不是将分支命名为:bugFix/UserName/BranchName,它在Git控制台上被写成bugFix/UserName/BranchName(注意这里小写的f)。 我通过输入git branch -a并将所有现有的分支与我签出/想要推送的分支进行比较来计算出这一点。控制台是如何出现小写f的,我仍然不知道。当然,如果实际本地分支的名称与您在推送时输入的名称不同,则该名称不能解析为分支!

在我的SmartGit GUI中,提交是在正确的分支上,但我更喜欢控制台和从那里推送,所以SmartGit更像是一个检查本地状态日志的步骤,并比较控制台中是否有一些错误。

我从中学到的是:

如果你的目标只是推送一个本地分支,就不要像一些人在有关这个错误的文章中建议的那样使用git push——all -u。

最好试着弄清楚到底哪里出了问题以及原因。然后寻找解决方案。也许你也有一个拼写错误或一些类似的不一致。

对于我的例子,我曾经有一个大写字母的分支文件夹(或者不管它叫什么),然后我用差分大小写(小写)创建了一个新文件夹,但git实际上用大写创建了分支。

I have created a branch like feature-ABC/branch1 before and pushed it. Then I create a branch feature-abc/branch2 (notice the lower-case ABC), and try to push it to remote using git push --set-upstream origin feature-abc/branch2 and get the 'cannot be resolved to branch' error. So I git branch and see that it actually created feature-ABC/branch2 instead of feature-abc/branch1 for me. I checkout again with git checkout feature-ABC/feature2 and push it using the uppercase (feature-ABC/feature2) to solve it.

Git将允许您使用不同的套管签出当前分支,并且它将无法在远程上找到引用。

这是我吃过苦头才知道的。

它是大小写敏感的,只要确保创建的分支和推送到分支都是相同的大写。

例子:

git checkout -b "TASK-135-hello-world"

错误的做法:

git push origin task-135-hello-world     #FATAL: task-135-hello-world cannot be resolved to branch

正确的做法:

git push origin TASK-135-hello-world

尝试这个错误:(feature/test是本地分支名称)

Git分支——set-upstream-to=origin/feature/test feature/test