2015-09-15 105 views
9

如何從git克隆分支?克隆分支時:在上游來源中找不到遠程分支

我知道這是一個愚蠢的問題,但我認爲我們一直在那裏犯了愚蠢的錯誤。

假設我有一個名爲branch-99的分支,我的用戶名是Christoffer。我嘗試像這樣克隆我的分支:

git clone -b branch-99 [email protected]/admin.git 

我收到此錯誤消息。

致命:遠程分支的分支-99不是上游產地發現

我怎麼能複製我的分支?

+1

您是否檢查過您的分支在遠程系統上可用?這可能是問題在這裏解決:http://stackoverflow.com/questions/25815127/github-clone-remote-brach-error-not-found。 – Calon

回答

11

branch-99在遠程存儲庫上不存在。您可能拼錯了分支名稱或存儲庫。

要檢查存在哪些分支,請正常克隆存儲庫並列出遠程分支。

git clone [email protected]:Christoffer/admin.git 
git branch -r 

另外,爲了避免克隆整個倉庫只是爲了檢查你可以用ls遙控器的分支,但你必須初始化倉庫和遠程手動添加。只有在存儲庫非常龐大並且不打算使用它的情況下才能執行此操作。

git init admin 
cd admin 
git remote add origin [email protected]:Christoffer/admin.git 
git ls-remote --heads origin 

要清楚,git clone -b branch-99 [email protected]:Christoffer/admin.git克隆整個存儲庫。它只檢查出branch-99而不是master。它與...

git clone [email protected]:Christoffer/admin.git 
git checkout branch-99 

這一點糖的語法是不值得費神的。我想這可能會節省你一小部分時間,而無需結賬主人。

如果您想克隆一個分支的歷史記錄以節省一些網絡和磁盤空間,請使用--single-branch

git clone --single-branch -b branch-99 [email protected]:Christoffer/admin.git 

然而它通常不值得麻煩。 Git的磁盤和網絡都非常高效。並且該分支的整個歷史都必須克隆,通常包括大部分存儲庫。

+0

是的,如果指定的分支不可用於git存儲庫,則會引發此錯誤。 –

1
git clone [email protected]:Christoffer/admin.git 
git checkout branch-99 
+0

如果'branch-99'不存在,這將無濟於事。 – Schwern

+0

當我使用git clone [email protected]:Christoffer/admin.git它克隆我的整個主人而不是分支-99 –

相關問題