Consider I am on master
and I have remote branch develop
on my remote named origin
, everything is up-to-date, I have already runned git fetch
.
Now is there any difference between git merge origin/develop
and git pull origin develop
?
Pull is a fetch + merge, and you explicitly merging from a remote *tracked branch, so there is no difference, even without the fetch.
if you give me a -1, at least comment what is your problem with my answer
Given the constraints you specified, and assuming that no one has changed anything on the remote since your git fetch
, the only difference is that the default commit message will be different. One will say merge branch 'origin/develop'
and the other will say merge branch 'develop' of 'url'
. If you provide or write your own merge message, there is no detectable difference at all.
(The hash ID of the resulting merge commit will depend on the time so if you try this yourself you are likely to get two different commits, unless you can do both within a single second. However, the hash ID of a future commit is effectively impossible to predict: you need to know what will be in it, including the timestamps.)
I would note that origin/develop
is not a branch; so the question seems more like "difference between git merge remote-tracking-ref and git pull remote branch" ...
I guess we can start with the simple but trivial: At a bare minimum, the default commit message will be different. But you probably don't care about that; most people pretty much ignore merge commit messages.
Beyond that, the question comes down to what assumptions are making.
To suppose that the commands are equivalent, we have to suppose a default configuration; because some config settings change what pull
does. (For example, pull
can be configured to rebase local changes instead of merging.)
It sounds like you want to assume that your local tracking ref and the remote branch both point to the same commit. That's generally an iffy assumption, because even though you "just did a fetch
", that doesn't preclude someone else doing a push
before you do your next command.
That said, it doesn't really matter. All that means is, if you do a merge you might end up behind (if someone happened to push right after your fetch); and it's not like doing a pull
is any better, because someone might do a push
right after your pull
... so if the world is out to get you, nothing you do will guarantee that nothing is in origin beyond what you have locally.
In fact, I'd say that if you just did a fetch, you're better off doing the merge instead of the pull, because the pull will do another fetch
that doesn't make much practical difference.