简体   繁体   中英

push rejection after a git rebase

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.`

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM