2017-07-06 133 views
1

我一直在Linux上使用git,沒有任何問題。不過,我最近不得不在Windows上使用git,所以我安裝了命令行客戶端,因爲這是我工作最愉快的方式。爲什麼Windows上的git無法識別遠程分支

我的問題是,我試圖檢出我在Linux上使用git checkout mybranchname創建的分支,但它沒有工作。我必須指定git checkout -b mybranchname --track origin/mybranchname

從那以後,每當我去推我得到告訴

fatal: The upstream branch of your current branch does not match 
the name of your current branch. To push to the upstream branch 
on the remote, use 

    git push origin HEAD:mybranchname 

To push to the branch of the same name on the remote, use 

    git push origin mybranchname 

To choose either option permanently, see push.default in 'git help config'. 

有誰知道爲什麼會這樣或如何解決它?

我在Linux上使用git版本2.12.0.windows.1和2.11.0。在兩種情況下,我的起源都是SSH上的GitHub Enterprise。

+0

你確定你已經拼寫正確的分支?我問,因爲你說檢查一個現有的分支「沒有工作」。問題是,它應該**。如果你從遠程獲取,'git branch -a'將分支列爲'origin/mybranchname',那麼'git checkout mybranchname'應該創建一個本地分支並自動跟蹤遠程分支。既然你所說的是「它沒有用」,很難猜測問題是什麼。 –

+0

我已經複製並粘貼它,所以我確信我的一切都正確 - 除了我在那裏有一個看不見的控制字符太多了。請參閱下面的答案。 – mjaggard

回答

3

在第一個命令中,您檢出必須已存在的本地分支。在第二個命令中,您正在創建新的本地分支並與遠程分支關聯。

情景是不同的。

如果本地分支之前並不存在,我會跑:

git branch mybranchname origin/mybranchname -u 

-u選項設置遠程分支是本地分支的上游,所以你可以做:

git push 
git pull 

而不必限定遠程:

git push origin mybranchname 
git pull origin mybranchname 
0

答案是混帳的Windows不知何故加入聯合國icode字符添加到無法在命令提示符中顯示的分支名稱。

我的一個分支被稱爲mybranchname但不知什麼原因被稱爲遠程分支\u0096mybranchname

解決方案(我並沒有要求這一點!):刪除Windows和永不再犯使用可怕的OS的錯誤這是很糟糕的小文件IO和隨機忽略命令窗口中的字符。