Git 更新fork后的本地仓库

第一步:配置remote upstream仓库

  1. 打开Git Bash界面

  2. 查看当前fork仓库的remote仓库配置信息

$ git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

  1. 配置当前fork仓库的upstream仓库地址(即fork的原仓库地址)

$ git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git

  1. 查看配置结果

$ git remote -v
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)
origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)
upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (fetch)
upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git (push)

参考文档:Configuring a remote for a fork

第二步:通过fetch拉取更新

  1. 打开Git Bash界面
  2. 通过fetch命令从upstream仓库取得需要的更新,fetch后会被存储在一个本地分支upstream/master上

$ git fetch upstream
remote: Counting objects: 75, done.
remote: Compressing objects: 100% (53/53), done.
remote: Total 62 (delta 27), reused 44 (delta 9)
Unpacking objects: 100% (62/62), done.
From https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY> * [new branch] master -> upstream/master

  1. 切换到本地master分支,将upstream/master分支合并到master分支

$ git checkout master

$ git merge upstream/master

**以上三步可以合并为一步:$ git pull upstream master,不过fetch + merge 更可控一点

参考文档:Syncing a fork

第三步:如果需要github上fork的仓库同步更新,则执行git push进行推送

git push origin master

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值