版權(quán)聲明:本文為CSDN博主「西京刀客」的原創(chuàng)文章,遵循CC 4.0 BY-SA版權(quán)協(xié)議,轉(zhuǎn)載請附上原文出處鏈接及本聲明。
原文鏈接:https://blog.csdn.net/inthat/article/details/124779375
0、背景
github fork了https://github.com/xxx/xxx.git后一段時間,同步更新正常。
當(dāng)https://github.com/xxx/xxx.git新增了分支testbranch,如何持續(xù)一致地同步更新?
基于git標(biāo)準(zhǔn),原始倉庫為upstream,克隆倉庫為origin:
upstrean: https://github.com/xxx/xxx.git
origin: https://github.com/yyy/xxx.git
git本地庫: 當(dāng)前僅知道origin,不知道upstream
1、查看本地的遠(yuǎn)端倉庫,并添加 upstream 上游倉庫
git remote -v
git remote add upstream https://github.com/xxx/xxx.git
git remote -v
2、直接從 upstream 獲取新分支 testbranch 到本地
git fetch upstream
git checkout -b testbranch upstream/testbranch
3、推送本地的新分支 testbranch 到 origin 上游倉庫
git push origin testbranch
4、在github中,可以查看到分支testbranch已經(jīng)存在并與主庫同步一致