Difference between git merge master and origin/master? Difference between git merge master and origin/master? git git

Difference between git merge master and origin/master?


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.

Read https://stackoverflow.com/a/7104747/2961170 for more information.


Using git merge origin/master refers to the master branch on the server. git merge master refers to your local master branch.

By using git pull you can merge them if they diverge.


master is your local branch, origin/master is remote branch (the state it was at last fetch)

The output you have shows that there's a commit in remote, that will overwrite sample.txt and is not yet pull'ed into your local master

As a rule of thumb - it's always better to have a clean working tree and up-to-date branches before doing any merging/rebasing etc.

So - commit your work, check git status, then do git pull --rebase ('oh-my-zsh' has alias gup for this) and only then proceed with merging.