Suppose developers are using git centralized workflow and github has 2 files a.txt and b.txt.
Now dev1 pushes c.txt successfully. Now if dev2 pushes d.txt, it's non fast-forward and he can't push and RIGHTLY SO, because he must first merge changes of dev1 locally and then push.
Now another scenario, Suppose dev1 creates branch featureC and has file c.txt in it along with a.txt, b.txt and pushes. Similarlty dev2 creates branch featureD and has file d.txt in it along with a.txt, b.txt and pushes.
Now pull request is made to merge featureC with master and it's successful. Again pull request is made to merge featureD with master and this SHOULD NOT be successful, but IT IS. IT CAN'T BE!! HOW COULD IT BE? Doesn't it match the above scenario?
There is a substant difference between push and pull. When you want to push commits onto a remote branch, you local repo needs all commits from the remote and of course the commits you want to push. That is not the case when dev2 pushes the commit for d.txt, while not knowing anything of the previous commit, that introduced c.txt.
Now with pull requests, the situation is different. You always can savely pull anything that does not conflict, which is the case when the commits affect different files only.
Actually it's a pull request, in your first case, when git tells dev2 to pull (merge) before he pushes.
You can always pull (fast-forward or merge) when there are no conflicts but you can only push when your branch is up-to-date with the remote branch you want to push to.
How to understand what gets commited
It's quite easy for a developer in a local repository to see what changes actually are requested by a commit. Assumed dev1 branched to featureA to develop some feature from master, this morning. In the evening he wants to see all changes he did and when he checked in, he yould do
All commits numbered in order are written to files
NUMBER-TITLE.patch
.All these patches can be merged to
origin/master
regardless of the state oforigin/master
(if there are already new changes went toorigin/master
, or not), when no patch fails to apply to origin/master, ordered by the number.