5

Git fork的仓库如何再同步原仓库?

 3 years ago
source link: https://www.leixuesong.com/3912
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Git fork的仓库如何再同步原仓库?

Linux 版本控制 2021年1月18日

Git使用过程中,fork可以将别人的仓库复制一份到自己的仓库。这样就可以在原仓库的基础上,继续开发,并可以在自己的仓库进行版本控制。那么如果fork的原仓库更新了或者修复一些bug,如何保持自己的仓库既能保留自己的修改,又能更新原仓库的修改呢?下面雷雪松给大家分享下fork的仓库如何再同步原仓库的方法。

1、给fork的仓库配置一个remote。
git remote add upstream https://github.com/ORIGINAL_OWNER/ORIGINAL_REPOSITORY.git
查看远程状态
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)

2、从上游仓库 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
切换到本地分支
git checkout master

3、把 upstream/master 分支合并到本地 master 上,完成原仓库同步,并且不会丢掉本地修改的内容。
git merge upstream/master
# Updating a422352..5fdff0f
# Fast-forward
# README | 9 ——-
# README.md | 7 ++++++
# 2 files changed, 7 insertions(+), 9 deletions(-)
# delete mode 100644 README
# create mode 100644 README.md

4、将自己的修改提交给原仓库,直接 git push origin master 就好了,原仓库会收到一个pull request请求。

来源:Git fork的仓库如何再同步原仓库?

发表评论 取消回复

邮箱地址不会被公开。 必填项已用*标注

评论

姓名 *

电子邮件 *

站点


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK