到目前爲止,您只添加了b作爲遠程。您可以嘗試git branch -a
在您提取遠程分支後列出您的遠程分支。
這裏的命令,從B籤的Z分支:
git remote add b /b # you've already done
git fetch b # get it so we can see it
git checkout -t b/z # check out a local tracking branch
的-t
(或--track
)創建了一個跟蹤分支,否則你會在分離的頭的狀態。
那麼你應該看到:
/a$ git branch
master
* z
對於任何人所涉及的步驟不明確,這裏就是我所做的:
創建起源
$ mkdir origin
$ cd origin/
/origin$ git init --bare
Initialized empty Git repository in /origin/
/origin$ cd ..
克隆 'a' 和添加一些內容
$ git clone origin/ a
Initialized empty Git repository in /a/.git/
warning: You appear to have cloned an empty repository.
$ cd a
/a$ echo hi there > hello
/a$ git add hello
/a$ git ci -m'first commit'
[master (root-commit) 0867b93] first commit
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 hello
/a$ git push origin master
Counting objects: 3, done.
Writing objects: 100% (3/3), 210 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
To /origin/
* [new branch] master -> master
克隆 'B',並添加更多的內容在新的分支
/a$ cd ..
$ git clone origin/ b
Initialized empty Git repository in /b/.git/
$ cd b
/b$ git checkout -b z
Switched to a new branch 'z'
/b$ echo new guy reporting in >> hello
/b$ git ci -am "new recruits"
[z 81044ee] new recruits
1 files changed, 1 insertions(+), 0 deletions(-)
增加 'B' 當作遙控 'A'
/b$ cd ../a
/a$ git remote add b ../b
/a$ git fetch b
remote: Counting objects: 5, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ../b
* [new branch] master -> b/master
* [new branch] z -> b/z
/a$ git br
* master
/a$ git checkout -t b/z
Branch z set up to track remote branch z from b.
Switched to a new branch 'z'
/a$ git br
master
* z
我把上面的commands into a script這樣你就可以自己測試一下。
我可能只是感到困惑,但它看起來像你在印象git分支是像顛覆分支(他們不是)的目錄。 – coreyward 2011-03-01 02:22:44
@coreyward:不,我認爲mit有兩個單獨的本地克隆 – idbrii 2011-03-01 02:39:24
「'git pull b z'」這是幹什麼的?分支z只存在於repo b中嗎?或者它實際上是從回購拉動? (我不希望它,因爲你沒有添加repo a作爲遠程repo b。) – idbrii 2011-03-01 18:30:01