惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Google DeepMind News
Google DeepMind News
The GitHub Blog
The GitHub Blog
Engineering at Meta
Engineering at Meta
N
Netflix TechBlog - Medium
Y
Y Combinator Blog
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
V2EX - 技术
V2EX - 技术
Webroot Blog
Webroot Blog
Google Online Security Blog
Google Online Security Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
AI
AI
N
News and Events Feed by Topic
S
Secure Thoughts
www.infosecurity-magazine.com
www.infosecurity-magazine.com
The Cloudflare Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
T
Tailwind CSS Blog
Vercel News
Vercel News
V
Vulnerabilities – Threatpost
Spread Privacy
Spread Privacy
Know Your Adversary
Know Your Adversary
人人都是产品经理
人人都是产品经理
I
Intezer
Schneier on Security
Schneier on Security
Martin Fowler
Martin Fowler
J
Java Code Geeks
K
Kaspersky official blog
H
Heimdal Security Blog
O
OpenAI News
I
InfoQ
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
云风的 BLOG
云风的 BLOG
Hacker News - Newest:
Hacker News - Newest: "LLM"
Blog — PlanetScale
Blog — PlanetScale
S
Schneier on Security
S
Security @ Cisco Blogs
Security Latest
Security Latest
PCI Perspectives
PCI Perspectives
H
Hacker News: Front Page
C
CERT Recently Published Vulnerability Notes
博客园_首页
The Last Watchdog
The Last Watchdog
罗磊的独立博客
L
LINUX DO - 热门话题
U
Unit 42
月光博客
月光博客
Security Archives - TechRepublic
Security Archives - TechRepublic
Scott Helme
Scott Helme

vzard's blog

二叉搜索树的一些性质 - vzard's blog 跳表 - vzard's blog redis的事务 - vzard's blog redis数据类型及使用场景 - vzard's blog 二叉树非递归遍历统一写法 - vzard's blog 灵魂七问 - vzard's blog XPath线索追踪技术 - vzard's blog cron表达式小记 - vzard's blog 计算广告核心问题总结 - vzard's blog 实现一个简单的http服务器 - vzard's blog 由三次握手想到的... - vzard's blog Js原型链解读 - vzard's blog 统计知识(1) - vzard's blog Http协议杂谈 - vzard's blog JAVA虚拟机的类加载机制 - vzard's blog HashMap源码剖析 - vzard's blog Java中的锁 - vzard's blog 关于volatile - vzard's blog 修复hexo博客的一个bug - vzard's blog
同步Github上的fork - vzard's blog
vzardlloo · 2017-10-13 · via vzard's blog

我们有时候会在Github上fork一个我们感兴趣的项目到自己的仓库,等一段时间过后这个项目已经更新了,但是自己仓库里还停留在刚fork时的状态,那么我们如何把自己fork到仓库的项目同步到作者的进度呢?这篇博客主要就是讲一下这个问题。
这个问题我有两种解决的办法:
一种是在Github上操作,把自己仓库的项目设成base,把作者的的项目设成head,然后给自己提pr,最后在pull下来就行了。这种方法的缺点就是要开网页点来点去,如果你正在沉迷在命令行里无法自拔可能不太喜欢这种方法。

第二种方法是在把作者的项目添加为自己的远程分支,然后需要同步的时候fetch一下这个远程分支,然后切换的本地分支(如果不在的话),然后把远程仓库合并到本地分支。具体方法如下:

  • 先查看一下自己的远程分支:

    1

    2

    3

    git remote -v

    # origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (fetch)

    # origin https://github.com/YOUR_USERNAME/YOUR_FORK.git (push)

  • 如果作者的仓库不在远程分支中,则把他添加到远程分支:

    1

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

  • 再次查看远程分支情况,确保已经加入:

    1

    2

    3

    4

    5

    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)

  • 从上游仓库 fetch 分支和提交点,传送到本地,并会被存储在一个本地分支 upstream/master

    1

    2

    3

    4

    5

    6

    7

    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

    2

    git checkout master

    # Switched to branch 'master'

  • 把 upstream/master 分支合并到本地 master 上,这样就完成了同步,并且不会丢掉本地修改的内容。

    1

    2

    3

    4

    5

    6

    7

    8

    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

  • 同步到Github上的自己的项目

    1

    git push origin master

OK,这个小问题都到此结束!