2012-12-14 94 views
7

我不知道,如果IM濫用的Git,或者如果我有一個配置問題,因此任何清晰度,將不勝感激:)的Git分支:跟蹤上游

我克隆我的github回購到機器A和B ,然後在機AI的更多信息:

git checkout -b branchA 
// make edits 
git add . 
git commit -am "initial" 
git push 

然後在機器B I做

git pull 
git checkout branchA 
// make edits 
git commit -am "edits" 
git push 

機器A i,那麼這樣做:

git pull 

但是它說:

There is no tracking information for the current branch 

,所以我必須做的:

git branch --set-upstream branchA origin/branchA 

:/爲什麼我必須設置上游,當它最初它推到原點/ branchA沒有問題?

怎麼回事?謝謝

即時通訊使用msygit 1.8。在窗戶上

P.S.當我在機器B上執行pull時,爲什麼默認跟蹤新分支branchAgit branch does not show it(but it does with -r)。我可以讓所有新的遠程分支被默認跟蹤,當我pull?

+0

是什麼在你的倉庫'混帳配置push.default'的輸出?它不會是'現在',是嗎? – jszakmeister

+0

它不返回任何東西(在機器A上):/ –

回答

12

因爲git config push.default不返回任何東西,這意味着,以「混帳1.8.0.msysgit.0」,您git push意味着git push origin :,用的Refspec「 ':'代表「匹配」分支。

這裏它在遠程端創建匹配branchA

但是,這並沒有使它成爲一個遠程跟蹤分支。
換言之,branch.branchA.merge未設置爲任何值。
這就是爲什麼git pull失敗:它不知道它應該合併到本地的哪個遠程分支branchA


注意,你的第一個git push應該顯示以下信息:

warning: push.default is unset; its implicit value is changing in 
Git 2.0 from 'matching' to 'simple'. To squelch this message 
and maintain the current behavior after the default changes, use: 

    git config --global push.default matching 

To squelch this message and adopt the new behavior now, use: 

    git config --global push.default simple 

See 'git help config' and search for 'push.default' for further information. 
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode 
'current' instead of 'simple' if you sometimes use older versions of Git) 

因此,隨着Git2.0,那混帳推將失敗。
branchA將通過設置明確其上游分支(使用相同的名稱)的唯一方法:

git push -u origin branchA 
+0

這是合理的,謝謝。那麼是否有一個配置設置來防止這種行爲(即,使'git push' /'git push origin:'創建一個遠程跟蹤分支?)還是我總是必須'push -u'? –

+0

@AndrewBullock你應該首先使用'-u'。之後,你不需要它。同時將默認推送模式設置爲簡單幫助強制本地分支與遠程跟蹤分支之間的對應關係。 – VonC

+0

@AndrewBullock表示,上游模式可以在這裏幫助你,如果你不想明確地使用'-u':請參閱http://stackoverflow.com/a/13751847/6309 – VonC