【问题标题】:Why can't I push my new branch?为什么我不能推送我的新分支?
【发布时间】:2012-12-06 12:16:33
【问题描述】:

我创建了一个新分支,检查并提交:

git branch my-branch [HASH]
git checkout my-branch
git commit -am "Add some stuff to my new branch"

但是,我无法将其推送到 github。 git push origin my-branch 返回:

error: src refspec branch does not match any.
error: failed to push some refs to 'https://github.com/Me/my-project.git'

git show-refs 看起来像这样:

[HASH] refs/heads/my-branch
[HASH] refs/heads/master
[HASH] refs/heads/some-branch
[HASH] refs/remotes/origin/master
[HASH] refs/remotes/origin/some-branch
[HASH] refs/stash

我需要做什么?

【问题讨论】:

标签: git github git-branch


【解决方案1】:

这是您将执行的命令,以将所有更改从本地分支(“my-branch”)推送到 GitHub 存储库上的“my-branch”分支:

git push -u origin my-branch

【讨论】:

    【解决方案2】:

    该分支在 github 上不存在,当您推送时 git 检查您的分支的 refs 并没有找到它。

    将分支添加为远程分支:

    git 1.8.x

    git branch -u origin/my-branch my-branch
    

    git 1.7.x

    git branch --set-upstream my-branch origin/my-branch
    

    现在你可以推送了。

    【讨论】:

      【解决方案3】:

      命令行解析出错。正如您在此消息中看到的:

      error: src refspec branch does not match any.
      

      git 尝试推送名称为 branch 的分支,而不是 my-branch。您正在运行什么操作系统/外壳?可以试试

      git push origin "my-branch"
      

      【讨论】:

        猜你喜欢
        • 2015-09-09
        • 2017-01-29
        • 2023-02-06
        • 2013-01-26
        • 2012-11-25
        • 2011-10-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多