如何将git远程分支更新到本地
来源:互联网 发布:淘宝外卖点麻辣烫 编辑:程序博客网 时间:2024/05/01 02:14
(1)先下载
git clone URL
(2)再切换到分支JarSample
git checkout JarSample
(3)从远程的origin仓库的master分支下载代码到本地的origin JarSample
git fetch origin JarSample
(4)强制更新,以远程覆盖本地
git checkout --force
【以下是参考的转载文章】
如何更新下载到代码到本地,请参阅ice的博客基于Github参与eoe的开源项目指南
方式一
1. 查看远程仓库
123456
$ git remote -veoecn https://github.com/eoecn/android-app.git (fetch)eoecn https://github.com/eoecn/android-app.git (push)origin https://github.com/com360/android-app.git (fetch)origin https://github.com/com360/android-app.git (push)su@SUCHANGLI /e/eoe_client/android-app (master)
从上面的结果可以看出,远程仓库有两个,一个是eoecn,一个是origin
2 ,从远程获取最新版本到本地
1234
$ git fetch origin masterFrom https://github.com/com360/android-app * branch master -> FETCH_HEADsu@SUCHANGLI /e/eoe_client/android-app (master)
$ git fetch origin master 这句的意思是:从远程的origin仓库的master分支下载代码到本地的origin master
3. 比较本地的仓库和远程参考的区别
12
$ git log -p master.. origin/mastersu@SUCHANGLI /e/eoe_client/android-app (master)
因为我的本地仓库和远程仓库代码相同所以没有其他任何信息
4. 把远程下载下来的代码合并到本地仓库,远程的和本地的合并
123
$ git merge origin/masterAlready up-to-date.su@SUCHANGLI /e/eoe_client/android-app (master)
我的本地参考代码和远程代码相同,所以是Already up-to-date
以上的方式有点不好理解,大家可以使用下面的方式,并且很安全
方式二
1.查看远程分支,和上面的第一步相同
2. 从远程获取最新版本到本地
1234
$ git fetch origin master:tempFrom https://github.com/com360/android-app * [new branch] master -> tempsu@SUCHANGLI /e/eoe_client/android-app (master)
git fetch origin master:temp 这句命令的意思是:从远程的origin仓库的master分支下载到本地并新建一个分支temp
- 比较本地的仓库和远程参考的区别
12
$ git diff tempsu@SUCHANGLI /e/eoe_client/android-app (master)
命令的意思是:比较master分支和temp分支的不同
由于我的没有区别就没有显示其他信息
4. 合并temp分支到master分支
123
$ git merge tempAlready up-to-date.su@SUCHANGLI /e/eoe_client/android-app (master)
由于没有区别,所以显示Already up-to-date.
合并的时候可能会出现冲突,有时间了再把如何处理冲突写一篇博客补充上。
5.如果不想要temp分支了,可以删除此分支
123
$ git branch -d tempDeleted branch temp (was d6d48cc).su@SUCHANGLI /e/eoe_client/android-app (master)
如果该分支没有合并到主分支会报错,可以用以下命令强制删除git branch -D <分支名>
总结:方式二更好理解,更安全,对于pull也可以更新代码到本地,相当于fetch+merge,多人写作的话不够安全。
如有错误请指正
声明:eoe文章著作权属于作者,受法律保护,转载时请务必以超链接形式附带如下信息
原文作者:
- 如何将git远程分支更新到本地
- git更新远程分支到本地
- Git 将本地新建的分支提交到远程仓库
- git fetch将远程分支信息获取到本地
- git push将本地分支推送到远程
- [CodeVersion--GIT]将远程仓库分支fetch到本地
- git提交本地分支到远程分支
- git 本地分支提交到远程分支
- git 更新本地分支与远程同步
- git 分支管理 推送本地分支到远程分支等
- git 分支管理 推送本地分支到远程分支等
- git 分支管理 推送本地分支到远程分支
- git 分支管理 推送本地分支到远程分支等
- git 分支管理 推送本地分支到远程分支等
- git 更新远程代码到本地和将本地代码推送到远程。
- git查看远程代码更新,合并到本地分支,以及远程代码的回滚
- git 获取远程分支代码到本地
- git 拉去远程分支到本地
- C语言中宏定义(#define)时do{...}while(0)的价值
- js函数的闭包
- js事件的分类和介绍
- Composer更新缓慢的解决方案
- 在布局中使用include引入其他layout时引发click事件不触发的问题
- 如何将git远程分支更新到本地
- python中新手常见的17个错误类型
- JAVA学习路线
- 长轮询 Servlet实现
- Lenovo X3650 M5 安装 ESXi-5.5.0u3 报错failed to resolve circular relocation
- 数组和链表的区别
- sigslot库的简单使用
- ActivityMQ 事务
- 高并发基础之Java并发包