github上fork repo的问题

浏览:39日期:2023-11-06

问题描述

github上fork了一个repo,这个repo是复制了一份到我的账号里如果原始项目的某个分支update了,我fork过来的repo会自动更新吗?

很多同学没理解我意思,是这样,fork一个project之后git remote add upstream git_url此时git branch -a假设输出:masterorigin/masterorigin/devupstream/masterupstream/dev

如果运行git fetch upstream则upstream的各个分支被更新了,但我fork的分支origin/masterorigin/dev却并没有更新,是不是更新所有origin分支都需要merge之后手动push?如果project的branch很多,岂不非常麻烦?

问题解答

回答1:

If the original repo you forked your project from gets updated, you can add those updates to your fork by running the following code:

git fetch upstream# Fetches any new changes from the original repogit merge upstream/master# Merges any changes fetched into your working files回答2:

先得将原来的仓库指定为upstream:

git remote add upstream https://github.com/被fork的仓库.git

再执行楼上所说的命令:

git fetch upstream git merge upstream/master

相关文章: