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

Hari Krishnan
  • 5,992
  • 9
  • 37
  • 55
  • 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. – Romain Valeri Aug 26 '22 at 08:16
  • Yes. This works. I should force push it. You can post this as answer. :) – Hari Krishnan Aug 26 '22 at 08:44
  • https://stackoverflow.com/search?q=%5Bgit%5D+hint%3A+Updates+were+rejected+because+the+tip+of+your+current+branch+is+behind – phd Aug 26 '22 at 09:28

1 Answers1

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').

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61