Git 同步 Fork 项目
Github 全球最大的同性交友网站,这里拥有最前沿的IT技术创新,拥有最流行的开源项目,等等…,总之这里是我的知识仓库,每天都会在上面寻找,学习知识
扯远了,本篇解决对于fork的项目,如何进行源项目的更新和同步问题
远程仓库
- 查看fork项目的远程仓库信息
1
2
3git 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
5git 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)
同步源仓库信息
- 获取源仓库更新
1
2
3
4
5
6
7git 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 - 查看本地master分支
1
2git checkout master
Switched to branch 'master' - 合并源仓库更新到本地master分支
1
2
3
4
5
6
7
8git 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
同步源仓库branch
在git中master实质是一个特殊的branch,其它的branch的同步和master同步操作并不一样
1 | # 查看项目的所有分支 |
如果源仓库分支已被删除,那么可以在fork项目中删除源仓库已被删除的分支
1 | # 删除指定分支,并推送到远程仓库 |
同步源仓库tag
1 | # 获取源仓库的tag |
附录
- 同步你的 Fork 仓库
- Configuring a remote for a fork
- Syncing a fork