Updated file on local repo -> push to remote -> no merge?


confused a bit on this:

  1. I 've updated file on local repo, so that same file exists on remote repo as well ( edited file, added to stage, did commit)
  2. Now I wanted to push to remote. Was expecting I will need to pull/merge first (since its the same file) but it did not. I was able to push.

Why? How come there was no need to merge first? Ty


By default a push will try to fast-forward merge, and fail if it can’t do that. “Fast-forward merge” requires that the latest commit of the remote branch is a direct ancestor of what you are pushing.

So if you have a history like this, you can just push, and fast-forward will work (C can just be added to the remote branch):

remote: A - B

local:  A - B - C

On the other hand a history like this would require a merge first:

remote: A - B - C

local:  A - B - D