2010-12-02 94 views
3

我有一個分支的github庫(稱之爲repo-O並調用我的fork repo-F),它包含大約8個分支。已經做出幾個(100s)的提交來從其他貢獻者以及多個repo-O分支進行repo-O。現在我想將這些更改引入我的分叉回購(repo-F)。我不能使用fork隊列,因爲大約有3000個提交選擇,我寧願從命令行執行此操作。在Github上更新分叉存儲庫的多個分支

所以..我克隆了我的回購,添加了repo-O作爲遠程(上游)並提取了更改,然後合併原點/上游...然後推回到repo-F。

這似乎已申請更改到主分支,而不是任何其他分支....

我怎麼能重複上述過程,使「所有」分支更新一次?

感謝

回答

4

你要完成什麼是「關於回購-O每個遠程分支,創建同一個分支指向回購-O的分支,如果我沒有它或拉從本地分支信息無論是在repo-o的同一分支上,並最終將所有這些分支推向我的回購-f「。

假設你的遙控器都被真名叫repo-orepo-f,我喜歡的東西玩,在bash

for repo_o_branch in \ 
    $(git branch -a|grep repo-o|perl -nle's,^\s*repo\-o/,,;print $_'; 
do 
    (                \ 
     (git checkout $repo_o_branch        \ 
     && git pull --rebase repo-o $repo_o_branch)    \ 
     || (git checkout -b $repo_o_branch repo-o/$repo_o_branch) \ 
    ) && git push repo-f $repo_o_branch; 
done 

對於所有的「回購Ø分支」(由git branch -a爲「回購O/BRANCHNAME所示」,沒有‘空間和‘回購-O /’’的一部分),

  • 嘗試檢出的分支git pull --rebase repo-o branchname裏面,
  • 或者如果git checkout失敗(因爲您沒有該分支):簽出以repo-o的分支名稱命名的新分支,並將其指向repo-o的branchname。
  • 如果上述兩項中的任何一項成功,則將新創建或更新的分支名稱推送到您的repo-f。

季節的味道;對repo-f新的git克隆最佳試圖用添加到它的遠程repo-o,以防萬一出問題;)

+0

非常感謝,這是有道理的。 ..我希望有一種方法可以讓git自動合併所有分支,但是這個腳本看起來好像有用。謝謝 – mrwooster 2010-12-02 10:16:04

1

AWK版本的一些合併treaks

sync_all_branch() { 
    git fetch upstream 
    for upstream_branch in $(git branch -a |awk 'BEGIN {FS="/"} $2=="upstream" {print $3}') ; 
    do 
     if git checkout $upstream_branch 
     then 
      echo merge $upstream_branch 
      git merge -s recursive -Xours upstream/$upstream_branch 
     else 
      echo create $upstream_branch 
      git checkout -b $upstream_branch upstream/$upstream_branch 
     fi 
    done 
    git checkout master 
    git push --all 
}