2014-09-22 14 views
1

我從分支,比如克隆一個項目從GitHub,BR1使用Git,我已經克隆了分公司,並想升級到另一個遠程分支

git clone --branch br1 https://www.github.com/project/project /opt/project/ 

我想切換到分支BR2彷彿我已經這樣做從一開始:

git clone --branch br2 https://www.github.com/project/project /opt/project/ 

我不希望所有的分支機構在本地,只有我使用的一個,因爲我是一個的ressource有限VPS。

我可以這樣做嗎(第一行的僞代碼)?

git fetch origin/br2 
git branch -D br1 

編輯:這裏是我的.config

# cat .git/config 
[core] 
    repositoryformatversion = 0 
    filemode = true 
    bare = false 
    logallrefupdates = true 
[remote "origin"] 
    fetch = +refs/heads/*:refs/remotes/origin/* 
    url = https://www.github.com/project/project 
[branch "br1"] 
    remote = origin 
    merge = refs/heads/br1 
+0

也許[這](http://stackoverflow.com/questions/6368987/how-do-i-fetch-only-one-branch-of-a-remote-git-repository)可以幫助嗎? – 2014-09-22 08:24:06

+0

我不明白說什麼,你想刪除分支(BR1)? – 2014-09-22 08:24:56

+0

@Anjaneyulu Battula:是的,在取得分支br2後。 – lalebarde 2014-09-22 08:37:13

回答

2

最簡單的方法是:

  • 刪除當前的回購
  • 再次進行克隆

    git clone --branch br2 https://www.github.com/project/project /opt/project/ 
    

將在網絡活動限制到最低限度,就像一個自定義的獲取會(但克隆比取回這裏簡單)如果你想測試提取選項

git remote rm origin 
git remote add -t branch2 origin remote-url 
git fetch origin 
+0

我以爲抓取會節省很多帶寬,因爲兩個分支都有很多共同點。最初的克隆花了我大約10分鐘。 – lalebarde 2014-09-22 08:39:22

+0

@lalebarde true,我編輯了答案,讓你先測試抓取。 – VonC 2014-09-22 08:42:24

+0

謝謝VonC。當我嘗試'git remote add -t branch2 origin remote-url',我得到'致命的:遠程原點已經存在。' – lalebarde 2014-09-22 08:46:12