git 为什么我不能推送我的新分支?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13743468/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 15:03:12  来源:igfitidea点击:

Why can't I push my new branch?

gitgithubgit-branch

提问by fredley

I made a new branch, checked it out and made a commit:

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

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

However, I can't push it to github. git push origin my-branchreturns:

但是,我无法将其推送到 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-refslooks like this:

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

What do I need to do?

我需要做什么?

采纳答案by Peter van der Does

The branch doesn't exist on github, when you push git checks the refs of origin for your branch and doesn't find it.

该分支在 github 上不存在,当您推送 git 检查您的分支的原始引用但没有找到它时。

Add the branch as a remote branch:

将分支添加为远程分支:

git 1.8.x

git 1.8.x

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

git 1.7.x

git 1.7.x

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

Now you can push.

现在你可以推了。

回答by Mario Kutlev

Here is the command you would execute to push all of the changes from your local branch ("my-branch") to a "my-branch" branch on the GitHub repository:

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

git push -u origin my-branch

回答by Chronial

There is an error in command line parsing. As you can see in this message:

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

error: src refspec branch does not match any.

git tries to push a branch with the name branch, not my-branch. What OS/shell are you running? Maybe try

git 尝试推送一个名为 的分支branch,而不是my-branch. 你在运行什么操作系统/外壳?也许试试

git push origin "my-branch"