2013-03-26 182 views
2

我分叉了我的Github帳戶存在超過1000個提交和20個分支的存儲庫。更新叉Github回購與所有分支

然後我在本地機器上克隆它。

有什麼辦法可以更新我的本地機器的回購和我的Github的回購與原來的所有分支機構和提交?

回答

4

也許爲時已晚,但遲到的回答總比沒有好:

# add the upstream: 

git remote add upstream https://github.com/whoever/whatever.git 

#create a script to loop through the whole branches and merge changes or create them if not found 

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 
} 

# then call the script 

sync_all_branch 

#push changes to your remote repository 

git push --all 
如果你想變基上游枝頂端的樹枝

(刪除您所做的更改並沒有被合併到上游) ,你應該改變

git merge -s recursive -Xours upstream/$upstream_branch 

git rebase -s recursive -Xours upstream/$upstream_branch 

,並添加 「-f」,以他最後的命令

* sync_all_branch腳本是從https://stackoverflow.com/a/7766487/2481592

+0

很好的答案。 +1 – VonC 2014-02-02 10:07:19

相關問題