2017-02-04 88 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

相關問題