繁体   English   中英

用所有分支更新分叉的Github存储库

[英]Update forked Github repo with all branches

我在Github帐户上创建了一个存储库,该存储库具有1000多个提交和20个分支。

然后,将其克隆到本地计算机上。

有什么办法可以用原始的所有分支和提交更新本地机器的仓库和Github的仓库吗?

也许为时已晚,但迟到的回答总比没有好:

# 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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM