Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

同步你的 Github fork #48

Open
yanyue404 opened this issue May 19, 2019 · 0 comments
Open

同步你的 Github fork #48

yanyue404 opened this issue May 19, 2019 · 0 comments

Comments

@yanyue404
Copy link
Owner

yanyue404 commented May 19, 2019

前言

选择拥抱开源,无疑参与 github的开源项目是最好的选择,先从同步 fork 仓库开始做起!

一、确认本地 fork 仓库版本是否落后于原仓库

1. 查看 github fork 仓库后的 commit数量及提交日志

本地 clone 自己仓库 后的 commit log 日志,与 gihub 上一致

2. 查看原仓库的相关信息,比较

比较后得知:本地 fork仓库的版本落后于原始仓库

下一步计划,准备开始同步!

二、 同步

1. 查看本地仓库设置的远端仓库,是否有连接上游原始远端仓库

如果未连接上游仓库,添加远程仓库的变量地址

$  git remote -v

origin  https://github.com/xiaoyueyue165/taro.git (fetch)
origin  https://github.com/xiaoyueyue165/taro.git (push)
  • 添加上游仓库
$ git remote add upsteream https://github.com/NervJS/taro.git

  • 再次查看远程仓库指向地址列表,确认添加
$  git remote -v
origin  https://github.com/xiaoyueyue165/taro.git (fetch)
origin  https://github.com/xiaoyueyue165/taro.git (push)
upsteream  https://github.com/NervJS/taro.git (fetch)
upsteream  https://github.com/NervJS/taro.git (push)

2. fetch,取回原仓库的更新

$ git fetch upsteream

默认情况下,git fetch 取回所有分支(branch)的更新

3. 将 fetch 后的更新内容合并至主分支

所取回的更新,在本地主机上要用"远程主机名/分支名"的形式读取。比如upsteream主机的master,就要用 upsteream/master 读取。

$ git merge upsteream/master

此时会发现本地 master 分支的 commit 日志已经与原仓库的日志保持一致

  • 本地 master

  • 原始仓库

4.更新,推送至远端 master 分支

$ git push origin master

  • 自己 fork 的 仓库变化, commit 数量与 最新日志与原仓库一致

5. 同步远程的 tag

# 添加主仓库到 remote
git remote add upstream git@github.com:vant-ui/vant.git

# 拉取主仓库最新代码
git fetch upstream

# 切换至 main 分支
git checkout main

# 合并主仓库代码
git merge upstream/main

# 发布到自己 fork 的项目,origin 是自己的源地址

git push origin main

同步 tag

# 同步分支后查看合并后分支的 tag 版本情况,会看到很多 upstream 源才有的 tag
git tag

# 上一步如果不对再获取一下(可省略)
git fetch upstream --tag

# 把 tag 同步到自己的源
git push origin --tags

参考

@yanyue404 yanyue404 changed the title 同步 Github fork 同步你的 Github fork May 20, 2019
@yanyue404 yanyue404 added 工具集 and removed Github labels Sep 2, 2019
@yanyue404 yanyue404 added Css and removed 工具集 labels Oct 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant