我在git倉庫中有兩個分支,master
和mybranch
。 在添加第二分支之前從Git是一個本地文件夾,我只能看到第一個分支,符合市場預期:如何跟蹤遠程git分支?
xxx$ git branch
* master
在試圖獲取其他分支我試圖
xxx$git branch --track mybranch
返回
Branch origin/mybranch set up to track local branch master
這不是我想要的,因爲從我的理解我現在的本地分支mybranch
相同master
(對吧?)。
所以我有2個問題:
如何刪除這個支部?
我怎樣才能真正獲取遠程分支
mybranch
?
編輯我不想結帳mybranch
,我只是想獲取。
編輯2
在其中我創建分支(I克隆回購,創建mybranch
並推它的工作區W2:
$ git branch -vv
master c417738 [origin/master] <latest commit msg>
* mybranch 0c7dbac <latest commit msg>
在初始工作區W1(其中I第一推master
)
$ git branch -vv
* master 66bb412 <latest commit msg>
現在,如果我做一個在W1取:
$ git fetch
我仍然只有master
:
$ git branch -vv
* master 66bb412 <latest commit msg>
但是,如果我檢查我的遠程分支機構,既master
和mybranch
存在:
$ git branch -r
origin/master
origin/mybranch
所以fetch
沒有得到來自各分公司的數據,正如我預料的那樣...
編輯3
現在,隨着克拉斯Mellbourn的指示,我所做的:
git branch mybranch
而且添加了這些行到我的conf文件:
[branch "mybranch"]
remote = origin
merge = refs/heads/mybranch
現在檢查我的樹枝我得到:
$ git branch -vv
* master 66bb412 <latest commit msg>
mybranch 66bb412 [origin/mybranch: ahead 3, behind 8] <latest commit msg from master (?)>
爲什麼mybranch
指定的提交與master
指定的提交相同?爲什麼它會指定與master
相同的提交號碼?
你是對的實際分支名稱。我嘗試了'git checkout mybranch'並得到:'錯誤:您對本地文件的更改將被checkout覆蓋:<文件列表>'。我只想獲取分支,我不想更改我當前的分支(主)。那可能嗎? – jul
@jul如果你只是想獲取遠程分支,一個普通的'git fetch'就足夠了。如果你想不創建一個本地跟蹤分支,你可以使用'git branch mybranch'來創建它,然後'git branch -u origin/mybranch mybranch'使它跟蹤'origin/mybranch' –
我試過了'git fetch',但後來'git branch'仍然只返回'* master'('git branch -r'顯示兩個分支'master'和'mybranch')。 – jul