1

I'm working on the the feature branch called auth, which was branched out from master branch:

C1 (master)
 \ 
  C2-C3 (auth)

After I've made C3 commit, I pushed the auth branch to remote for backup. Then master branch is updated on remote and the history looks like this:

C1-C4 (master)
 \ 
  C2-C3 (auth)

I'm rebasing auth branch to updated master branch and the history now looks like this:

C1-C4 (master)
    \
     C2-C3 (auth)

Then I make more changes on auth branch, make C5 commit and push auth branch to remote and the push is rejected with the message that there are updates on remote that I don't have locally. But I know that no one else pushed to the auth branch on remote. So why is this behavior?

This article provides just a simple explanation for such behavior:

Beware though: if the rebased branch had been pushed to a remote (for backup purposes, for instance), you’ll need to force the next push of it with the -f option, as you just replaced its commit history with a fresh one.`

Max Koretskyi
  • 85,840
  • 48
  • 270
  • 414

1 Answers1

2

The rebase has changed the history of the auth branch.

That is why you need a forced push, which is OK only if you are the only one to work on this branch.
If not, it would be best to:

As in:

C1-----C4      (master)
 \      \
  C2-C3--M--C5 (auth)
Community
  • 1
  • 1
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • Thanks, VonC! I think to better understand your answer I'd need to know how git knows that there changes on remote that are not here, i.e. why git reports exactly this error. What's the topic to investigate or resource to read about that? – Max Koretskyi Jan 26 '15 at 09:42
  • 1
    @Maximus it is not really "changes that are not there". It is simply because the auth SHA1s on GitHub differ from the auth SHA1 you are trying to push (as illustrated in http://marklodato.github.io/visual-git-guide/index-en.html#rebase) – VonC Jan 26 '15 at 09:56
  • @Maximus `git rebase` changes the commits SHA1 by changing it's parent commit; this makes git consider the local commits to be different from the remote one. – Sascha Wolf Jan 26 '15 at 09:57