它看起來像設置一個非默認的refspec會讓我在那裏。
例如,考慮這設置:
初始化gamma
$ (mkdir gamma; cd gamma; git init; touch README; git add README;
git commit -m 'Initialized slave.'; git branch -m slave; echo)
Initialized empty Git repository in /tmp/test-git/gamma/.git/
[master (root-commit) 0cebd50] Initialized slave.
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README
beta
初始化並添加gamma
作爲遠程:
$ (mkdir beta; cd beta; git init; touch README; git add README;
git commit -m 'Initialized master.';
git remote add gamma ../gamma; git fetch gamma
echo; echo "In repo $(basename $PWD):"; git branch -a; echo)
Initialized empty Git repository in /tmp/test-git/beta/.git/
[master (root-commit) f6512e1] Initialized master.
0 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 README
warning: no common commits
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
From ../gamma
* [new branch] slave -> gamma/slave
In repo beta:
* master
remotes/gamma/slave
克隆beta
使alpha
:
$ git clone beta alpha
Initialized empty Git repository in /tmp/test-git/alpha/.git/
$ cd alpha; git branch -a
* master
remotes/origin/HEAD -> origin/master
remotes/origin/master
現在得到激烈:
# Avoid errors from pulling into active branch.
$ git checkout origin/master | head -3 # intentionally acquire severed HEAD
Note: checking out 'origin/master'.
You are in 'detached HEAD' state. You can look around, make experimental
$ git fetch origin '+refs/*:refs/*' # pour steroids into open esophagus
From /tmp/test-git/beta
* [new branch] gamma/slave -> gamma/slave
$ git branch -a
* (no branch)
master
remotes/gamma/slave
remotes/origin/HEAD -> origin/master
remotes/origin/master
$ git remote
origin
所以做了`$混帳取 '+參/ :裁判/' 會拉在分支本身,但不會更新構成它所屬遠程的配置項。
有趣的是,設定追蹤分支的remoteless遠程分支將導致其開始跟蹤自己的回購:
$ git branch --track slave gamma/slave
Branch slave set up to track local ref refs/remotes/gamma/slave.
$ git config -l | grep '^remote\|^branch'
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
remote.origin.url=/tmp/test-git/beta
branch.master.remote=origin
branch.master.merge=refs/heads/master
branch.slave.remote=.
branch.slave.merge=refs/remotes/gamma/slave
我覺得這並不真正發揮作用。
$ git checkout slave
Switched to branch 'slave'
$ git fetch
From .
* remote branch gamma/slave -> FETCH_HEAD
$ git fetch
From .
* remote branch gamma/slave -> FETCH_HEAD
我有點相同的情況;從上游獲取一個回購,然後在本地克隆相同的回購。上游回購是巨大的,我在移動互聯網上,所以我不想從上游獲取所有分支機構。有幾個問題「我如何獲取所有遠程分支機構?」有很多upvotes,簡單的答案通常是普通的克隆/獲取會做到這一點 - 但只有在使用「中央存儲庫」時纔是這種情況。 – tobixen 2015-02-21 10:38:15