赞
踩
1.目标分支和来源分支一致
语法
git push <remote> <place>//remote:远程仓库名,如origin,place:远程仓库中的分支名称
git push origin master;//将本地仓库中master的提交添加到远程仓库中master分支上(提交前先pull一下)
执行前
git checkout C0;
git push origin master;
执行后
push后面不添加参数
执行前后
git checkout C0;
git push;
//因为当前检出的是HEAD(在C0),没有跟踪任何远程分支,所以没有效果
例子练习
git push origin master;
git push origin foo;
2.目标分支和来源分支不一致
语法
git push <remote> <source>:<destination> //remote:远程仓库名,source:本地分支(来源分支),destination:远程仓库中对应的分支(目标分支)
//source 可以是任何 Git 能识别的位置
执行前
git push origin foo^:master//foo^:C2
执行后
如果远程仓库中的目标分支不存在,会自动创建对应的分支
执行前
git push origin master:newBranch//远程仓库中没有newBranch分支,会自动创建
执行后
例子练习
git push origin master^:foo;
git push origin foo:master
方式一
git fetch <remote> <branch>//remote:远程仓库名,branch:本地的远程分支与远程仓库对应的分支
git fetch origin master//将远程仓库中master分支的所有提交都下载到远程分支o/master(不是本地master分支)
执行前
git fetch origin foo;
//并没有更新本地的foo,因为没有进行合并
执行后
方式二
//source:远程仓库中的分支名,destination:是本地仓库的本地分支(不是本地的远程分支)
git fetch <remote> <source>:<destination>
执行前
git fetch origin foo^:bar
执行后
如果本地的目标分支不存在,也会自动创建
执行前
git fetch origin foo~1:bar//本地不存在bar分支。自动创建
执行后
如果git fetch后面没有参数,就会下载所有的提交记录到本地仓库中的各个远程分支(只会更新远程分支,不会更新对应的本地分支)
例子练习
git fetch origin foo:master;//将远程仓库中的foo分支下载到本地的master分支
git fetch origin master^:foo;//将C3下载到本地的master分支
git checkout foo;//切换到foo分支
git merge master;//将master分支合并到foo分支
git push/fetch <remote> <source省略不写>:<destination>;
git push origin :develop;
git fetch origin :develop;
执行前
git push origin :foo;//提交空的本地分支到远程仓库,会删除掉对应分支
执行后
执行前
git fetch origin :bar//下载空的分支到本地的bar分支,本地不存在bar分支,会新创建一个bar分支
执行后
例子练习
git push origin :foo;//删除远程仓库中的foo分支
git fetch origin :bar;//在本地仓库创建一个bar分支
git pull 是 fetch 后跟 merge 的缩写。git pull用同样的参数执行 git fetch,然后再 merge合并 抓取到的提交记录。
git pull origin foo;//git fetch origin foo; git merge o/foo;
git pull origin bar~1:bugFix;//git fetch origin bar~1:bugFix; git merge bugFix
执行前
git pull origin master;//通过指定了master,来更新远程分支o/master,然后再将o/master merge合并到当前的检出位置,无论我们当前检出的位置是哪(不是本地master分支也行)
执行后
执行前
git pull origin master:foo//会先创建分支, 然后再将远程仓库的master分支提交记录下载到本地的foo分支,最后再merge到当前检出的分支(bar)
执行后
例子练习
git pull origin bar:foo;//本地创建foo分支,将远程仓库中bar的提交记录下载到foo分支,然后再合并到当前检出的master分支上
git pull origin master:side;//本地创建side分支,将远程擦仓库中的master分支的提交记录下载到side分支,再合并到master分支
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。