0

I have my master branch as commitA <- HEAD

dev branch as commitA -> commitB -> commitC<- HEAD

feature branch taken from master as commitA -> commitD <- HEAD and pushed it to remote.

I have created the feature branch wrongly from master instead of creating it from dev.

Now I want to make my feature branch to look like commitA -> commitB -> commitC -> commitD<- HEAD, So I have done a rebase:

git rebase dev

The local branch looks like what I need now. But when I push it to remote, It is getting rejected with

! [rejected]          feature -> feature (non-fast-forward)
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.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

So I tried a git pull, Which makes the local branch looks something like:

commitA -> commitB <- HEAD. and it does not make any sense to me. So How can I fix my original problem of making my feature branch in remote to be commitA -> commitB -> commitC -> commitD<- HEAD

3
  • 3
    Instead of pulling, you should have pushed with --force-with-lease to replace the previous history (A - D) with the new one (A - B - C - D'). In a nutshell. Commented Aug 26, 2022 at 8:16
  • Yes. This works. I should force push it. You can post this as answer. :) Commented Aug 26, 2022 at 8:44
  • stackoverflow.com/…
    – phd
    Commented Aug 26, 2022 at 9:28

1 Answer 1

2

Short answer
Instead of pulling, you should have pushed with --force-with-lease to replace the previous history (A - D) with the new one (A - B - C - D').

Not the answer you're looking for? Browse other questions tagged or ask your own question.