github Git-fork-别人的项目后更新代码的方法

 用github还处于菜的阶段,遇到问题简单记录。
 
举个例子,需要 fork 这个项目 https://github.com/tarobjtu/WebFundamentals.git
点击 fork, 就会复制一份代码到自己的 repo https://github.com/laispace/WebFundamentals.git
本地 clone 自己 repo 中的这个项目
添加自己的远程仓库
$ cd WebFundamentals
 
修改代码后进行 push
$ git add --all
$ git commit -m 'edit some files'
$ git push
 
这时候,如果源仓库 tarobjtu 的项目代码进行了更新,而我们自己 fork 下来的代码想要合并这些更新怎么做呢?
添加源项目的远程仓库
$ git remote add tarobjtu https://github.com/tarobjtu/WebFundamentals.git // 这时候可以看到有两个源了
$ git remote
// laispace // tarobjtu
 
拉取源仓库的代码到本地
$ git fetch tarobjtu
 
合并源仓库的 master 分支代码到本地
$ git merge tarobjtu/master
 
提交代码到我们自己的仓库
$ git add --all
$ git commit -m '合并源仓库代码'
$ git push
这样自己的github就是最新的了,与原始的代码同步。有更新的代码贡献。 可以pull request
 
转自:https://github.com/laispace/laispace.com/blob/master/source/_posts/Git-fork-%E5%88%AB%E4%BA%BA%E7%9A%84%E9%A1%B9%E7%9B%AE%E5%90%8E%E6%9B%B4%E6%96%B0%E4%BB%A3%E7%A0%81%E7%9A%84%E6%96%B9%E6%B3%95.md
posted @   愤怒的企鹅  阅读(1362)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:基于图像分类模型对图像进行分类
· go语言实现终端里的倒计时
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
阅读排行:
· 25岁的心里话
· 闲置电脑爆改个人服务器(超详细) #公网映射 #Vmware虚拟网络编辑器
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 零经验选手,Compose 一天开发一款小游戏!
· 一起来玩mcp_server_sqlite,让AI帮你做增删改查!!
点击右上角即可分享
微信分享提示