Git操作pull & fetch

pull 和 fetch 区别


pull 作用相当于说从远程拉取某一个分支并且合并当前分支到该 分支:相当于做了两个动作:一个是拉取 一个是合并( merge ),产生的结果是,本地分支会有远程库所拉取分支的内容,但是并不会默认产生与远程名相同的分支

同样 fetch 会拉取远程分支到本地库,但是不会在本地创建与之名字相同的分支,如果想用远程的分支 可以 checkout 远程分支的名字就能切换到远程分支名字相同的分支 (创建了与远程库相同名字的分支并且切换到对应名字分支上去)

pull = fetch + merge

在分支操作中 pull 操作基本禁用,因为 不能随意合并分支。

所以操作远程库分支的标准操作是:

git fetch origin 远程分支名字:远程分支名字 既会拉取远程库分支到本地分支,并且在本地创建与之对应的分支

这个就是远程分支与本地分支的对应 push 一定是分支对分支

git push -u origin 分支名字:分支名字

这回长记性了 ,差点坏了大事

Hello, I am Mingyue Li. Read my thoughts on IT and Life

Copyright Declaration:

All articles and pictures contained on this web site is copyright protected. If reproduced, must contain this statement, and indicate the original author and the original address of this article