Difference between git merge <branch> and git merge origin <branch>

馋奶兔 提交于 2019-12-13 17:57:01

问题


This is not a question on git merge origin branch vs git merge origin/branch

git merge <branch> merges the into the working branch. And so we need to specify the "source" of the branch. It can be a locally available origin/<branch> or the local working branch heads/branch.

But what's the need for origin? Unlike git pull we don't need to specify which remote source to fetch the from. A merge operation, to my understanding, is a local operation.


回答1:


The git pull command lets you specify a default remote branch to be used for fetching, as well as the default target local branch as the merge target. It makes sense to do this, because typically a given local branch will only have one upstream on the remote.

On the other hand, the git merge operation could be happening with any source branch, with your local branch as the target. Therefore, it makes less sense to allow for defining a default source branch to be used in merging.

The one instance where a default source branch for merging would make sense is of course git pull, when you want to update your local version of the remote branch. But, this merge scenario is actually part of git pull, and usually is not done a separate merge.



来源:https://stackoverflow.com/questions/51626304/difference-between-git-merge-branch-and-git-merge-origin-branch

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!