![](/img/trans.png)
[英]How to correctly sync the master and branches on a forked repo from 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.