Difference between git merge and git merg

2019-08-02 17:05发布

问题:

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.



标签: git git-merge