git fetch && git merge origin/master
is different from
git fetch && git merge origin master # Invalid
because git fetch
updates .git/refs/remote/<remote server name>/<remote branch name>
. And unless specified, you're always referring to your HEAD
of the working directory, which is in .git/refs/heads/<branch name>
Note: git merge
is a local operation. git merge origin master
is an invalid operation. As discussed here SO question
Git fetch
git fetch
fetches information on remote branches, but does not make any changes to your local master
branch. Because of this, master
and origin/master
are still diverged. You'd have to merge them by using git pull
When you make a commit, your local master branch is ahead of origin/master
until you push those changes. This case is the opposite, where the origin/master
branch is ahead of your local master branch. This is why you are getting different outcomes
Source