GitHub 上有个很方便的功能叫 fork,将别人的工程一键复制到自己账号下。这个功能很方便,但有点不足的是,当源项目更新后,你 fork 的分支并不会一起更新,需要自己手动去更新,下面记录下网上找到的更新的开发方法。

1. 在本地装好 GitHub 客户端,或者 Git 客户端

2. clone 自己的 fork 分支到本地

可以直接使用 GitHub 客户端,clone 到本地,如果使用命令行,命令为:

$ git clone git@github.com:ehlxr/strman-java.git

3. 增加源分支地址到你项目远程分支列表中

此处是关键,先得将原来的仓库指定为 upstream,命令为:

$ git remote add upstream git@github.com:shekhargulati/strman-java.git

此处可使用 git remote -v 查看远程分支列表

$ git remote -v
origin  git@github.com:ehlxr/strman-java.git (fetch)
origin  git@github.com:ehlxr/strman-java.git (push)
upstream  git@github.com:shekhargulati/strman-java.git (fetch)
upstream  git@github.com:shekhargulati/strman-java.git (push)

4. fetch 源分支的新版本到本地

$ git fetch upstream

5. 合并两个版本的代码

$ git merge upstream/master

6. 将合并后的代码 push 到 GitHub 上去

$ git push origin master

参考网址:

https://help.github.com/articles/fork-a-repo

— The End —
Last modification:August 30, 2018
If you think my article is useful to you, please feel free to appreciate