标签:inxi xxxx git pull oca master highlight 写法 版本 如何
工作中,我们会用到git pull来从远程仓库"同步"代码,通常有三种方式;
git pull origin <remote_branch>:<local_branch> git pull origin <remote_branch> git pull
这三种用法充分诠释了什么是简即繁,繁即简;看上去简单的,往往背后蕴藏玄机;
测试环境: 本地分支:master和dev 远程分支:master和dev $ git branch -a * dev master remotes/origin/HEAD -> origin/master remotes/origin/dev remotes/origin/master
这种用法写起来最为繁琐,但最好理解:
场景:当本地的当前分支不是local_branch;
作用:将远程分支拉取到指定本地分支;
例如:当前分支是dev,但是你想把远程master”同步”到本地master,但又不想使checkout切换到master分支;
这时你就可以使用git pull origin master:master
zhangchangzhi@ZBXXXX /e/02.Workspace-test/gitTest (dev) $ git pull origin master:master From https://github.com/jinxintang/gitTest a09fdc4..941758f master -> master Already up-to-date.
从上述代码可以看到,我当前分支为dev,但执行"同步”操作的却是在master分支;
有了上面的例子,这种使用方法的场景和作用就好理解了:
场景:在当前分支上进行同步操作;
作用:将指定远程分支同步到当前本地分支;
zhangchangzhi@ZBXXX /e/02.Workspace-test/gitTest (dev) $ git pull origin master From https://github.com/jinxintang/gitTest * branch master -> FETCH_HEAD Already up-to-date.
把远程master分支同步到HEAD分支(HEAD分支指向当前位置);
这种写法最简单,也最常用,但是隐含的知识也是最多的;
场景:本地分支已经和想要拉取的分支建立了“关联”关系;
作用:拉取所有远程分支的新版本"坐标",并同步当前分支的本地代码(具体根据关联分支而定)
首先我们先使用git branch -vv
查看一下目前分支的“关联”情况;
$ git branch -vv * dev 1a1b215 [origin/dev] Merge branch ‘master‘ of https://github.com/jinxintang/gitTest into dev master a09fdc4 [origin/master] create pull
git checkout -b dev origin/dev
git push -u origin <remote_branch>
或git push --set-upstream origin <remote_branch>
zhangchangzhi@ZB-PF0SB6DQ MINGW64 /e/02.Workspace-test/gitTest (dev_zcz) $ git branch -vv * dev_zcz 3b7001a [origin/dev] cm master a09fdc4 [origin/master] create pull zhangchangzhi@ZB-PF0SB6DQ MINGW64 /e/02.Workspace-test/gitTest (dev_zcz) $ git push -u origin dev_zcz Everything up-to-date Branch dev_zcz set up to track remote branch dev_zcz from origin. zhangchangzhi@ZB-PF0SB6DQ MINGW64 /e/02.Workspace-test/gitTest (dev_zcz) $ git branch -vv * dev_zcz 3b7001a [origin/dev_zcz] cm master a09fdc4 [origin/master] create pull
通过上面的例子可以看到push前dev_zcz关联的是origin/dev,执行push -u 后管理分支改为origin/dev_zcz
注:默认配置下,提交时本地分支需和远程分支同名
转载地址:https://www.jianshu.com/p/55b6720264ee
标签:inxi xxxx git pull oca master highlight 写法 版本 如何
原文地址:https://www.cnblogs.com/weidaijie/p/10893494.html