Github-如何在更新代码的同时使分叉的仓库与原始仓库保持同步 [英] Github - how to keep your forked repo in sync with the original while updating the code

查看:108
本文介绍了Github-如何在更新代码的同时使分叉的仓库与原始仓库保持同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,我几乎处于一个开源项目的第一个PR阶段.我知道如何使我的分叉/本地仓库与原始仓库保持同步.但是自上个星期以来,我一直在为代码做贡献,与此同时,原始存储库又进行了新的提交.

So I am almost at the point of my 1st PR at an open source project. I know how to keep my forked/local repo in sync with the original. But I am contributing to a code since last 1 week and in the meantime, the original repo got ahead with new commits.

那么我该如何在不丢失我在本地所做的更改的情况下,将派生/本地存储库与原始存储库同步呢?

So how should I sync my forked/local repo in sync with the original without loosing the changes I made locally?

推荐答案

您的本地存储库可以有多个远程存储库.如果您在GitHub之类的地方创建了一个仓库,然后在本地克隆了仓库,则您已经有一个远程控制器,可能称为origin.您可以做的是在本地仓库中添加第二个远程服务器,称为upstream:

Your local repo can have more than one remote repo. If you forked a repo on a place like GitHub, and then cloned that locally, you already have one remote, probably called origin. What you can do is add a second remote to your local repo, called something like upstream:

git remote add upstream https://original/repo/url
git fetch upstream

现在,假设您已经在名为my-feature的本地分支中进行工作,并且想要使用上游仓库中master的最新更改来对其进行更新.

Now let's say you've been doing work in a local branch called my-feature, and you want to update it with the most recent changes from master in the upstream repo.

git checkout my-feature
git merge upstream/master

然后,您解决所有冲突,将合并提交到本地存储库,然后像其他任何提交一样将更改推送到origin.

Then you resolve any conflicts, commit the merge to your local repo, and push the changes to origin like any other commit.

这篇关于Github-如何在更新代码的同时使分叉的仓库与原始仓库保持同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆