I have pushed a feature branch to github that I realized I want to rebase in order to squash some commits. I run
git rebase HEAD~5
on my local branch and set all but the first and last commit to "fixup". I save and quit and the rebase continues fine. When I try to push I get
error: failed to push some refs to 'git@github.com:username/repo.git'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
Is there a way to do this without push -f or is that my only recourse? Is there a better way to squash the commits?
The only way is with git push -f
. The commits you removed (by replacing them with a single squashed one) are already on the remote. Without -f
, you can only add commits, not remove/replace them.
On the other hand, if nobody has pull
ed yet, it shouldn't be a problem.
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.