2017-02-04 86 views
2

我从主分支创建了一个功能分支,并向我的分支添加并提交了一些更改。错误:src refspec我的分支不匹配任何

现在我想推动我的工作到远程存储库,但它失败了。我能做些什么来解决这个问题?谢谢。

运行git push命令时,它没有要求输入我的密码。这是正常的吗?

p.s.我正在使用Windows 10的cmd。

> git push origin my-branch 
error: src refspec my-branch does not match any. 
error: failed to push some refs to 'https://git.xxx.net/Infrastructure' 


>git commit -m "my work" 
On branch my-branch 
nothing to commit, working tree clean 

>git branch 
    master 
* my-branch 

>git show-ref 
687f22d54b89e0de91f16cf79d52c6ea21a3f562 refs/heads/master 
f85d2aa0900fb356d8d120f454ff2362d7475edb refs/heads/my-branch 
687f22d54b89e0de91f16cf79d52c6ea21a3f562 refs/remotes/origin/HEAD 
687f22d54b89e0de91f16cf79d52c6ea21a3f562 refs/remotes/origin/master 


>git log 
commit f85d2aa0900fb356d8d120f454ff2362d7475edb 
Author: tim <[email protected]> 
Date: Fri Feb 3 23:50:43 2017 -0500 

    my work 

commit 687f22d54b89e0de91f16cf79d52c6ea21a3f562 
Author: Kevin <[email protected]> 
Date: Thu Jan 19 12:26:26 2017 -0500 

    Added gitignore 
+0

你有没有在'my-branch'中提交? 'git log'输出? –

+0

对于'git log'输出,请参阅添加的。我怎么知道我是否在我的分支中有任何提交? – Tim

回答

1

试试这个:

$ git push origin HEAD:my-branch 
    Or, 
    $ git push -u origin my-branch 

git push origin HEAD:my-branch push the current branch to the remote ref matching my-branch in the origin repository. This form is convenient to push the current branch without thinking about its local name .

Vs的

git push origin my-branch find a ref that matches my-branch in the source repository (most likely, it would find refs/heads/my-branch), and update the same ref (e.g. refs/heads/my-branch) in origin repository with it. If my-branch did not exist remotely, it would be created.

+0

谢谢。你能解释一下可能是我的问题以及你写的命令是做什么的吗? – Tim

+0

谢谢。为什么git push -u origin my-branch'工作,而'git push origin HEAD:my-branch'不能用同样的错误工作? – Tim

+0

这里,不知何故'local/my-branch'没有找到远程跟踪分支(“'错误:src refspec my-branch不匹配任何”)。因此,'-u = --set-upstream'标志和“git push”告诉git跟踪新创建的远程分支('my-branch')。 –

2

默认情况下,push policy is simple (since Git 2.0)
这意味着Git会尝试推送到以本地名称命名的远程分支。

如果您没有该名称的任何远程分支,您需要明确声明您要创建并推送所述远程分支。
请参阅 “Why do I need to explicitly push a new branch?

your local first push has no idea:

  • where to push
  • what to push (since it cannot find any upstream branch being either recorded as a remote tracking branch, and/or having the same name)

通过添加git push -u origin my-branch,你会联想到你的本地分行远程(branch.<name>.remote)和目标(origin/mybranchbranch.<name>.merge

下推动将是一个简单的git push

相关问题