2011-02-18 184 views
1

我想獲取遠程分支的遠程分支。提取遠程遠程分支和遠程分支

因此,例如,在這種情況下 -

$ cd alpha 
$ git remote 
beta 
$ git branch -a 
master 
remotes/alpha/master 
$ cd ../beta 
$ git remote 
gamma 
$ git branch -a 
master 
remotes/gamma/slave 

- 我想通過beta去取水gammaslave支進alpha庫。這可能會增加gamma作爲alpha的遠程,並使用gamma/slave作爲新分支的參考。我不一定要創建一個本地跟蹤分支。與示例中不同的是,我也不一定有文件系統訪問betagamma

這樣的事情可以用$ git clone --mirror完成,但有沒有辦法在已經存在的回購中做到這一點?

+0

我有點相同的情況;從上游獲取一個回購,然後在本地克隆相同的回購。上游回購是巨大的,我在移動互聯網上,所以我不想從上游獲取所有分支機構。有幾個問題「我如何獲取所有遠程分支機構?」有很多upvotes,簡單的答案通常是普通的克隆/獲取會做到這一點 - 但只有在使用「中央存儲庫」時纔是這種情況。 – tobixen 2015-02-21 10:38:15

回答

0

它看起來像設置一個非默認的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