A Rejected Push

This is the error everyone hits eventually, and it is git protecting someone else's work.

If origin has commits you have never seen, accepting your push would strand them. So git refuses, and the fix is always the same: bring their work down, integrate it, then push the combined result.

pull is the shortcut for the first two steps — fetch and merge in one command.

push --force overrides the refusal instead of resolving it. It does not merge their work — it replaces origin's branch with yours and leaves their commit attached to nothing. Reach for it only on a branch you are certain nobody else is using.

Exercises

  1. Exercise 1. Try pushing first and read the refusal. Then recover the way git wants you to, and get your work onto origin.
  2. Exercise 2. Now the escape hatch — and its cost. Force the push through, then look at origin: their commit is still there, on no branch at all. That is work you just made very hard to find.
  3. Exercise 3. Same situation, but do it the explicit way this time: fetch, merge, then push. This is exactly what pull did for you above.