-1

Scenario: I have two branches: develop and feature_xyz. I'm integrating feature_xyz into develop via merge request in Gitlab but I'm facing a non fast-forward scenario so I must rebase develop into feature_xyz locally and then push and request again.

But I'm facing a loop rebase problem: locally after rebase develop into feature_xyz, when I try to push the local feature_xyz branch to the remote I'm getting an error saying that my local branch is behind its remote counterpart. Rebase the remote into my local feature_xyz branch and push it works pretty fine but if I try to rebase the develop into my feature_xyz local branch again I will face the same error if I try to push to the feature_xyz remote branch.

How could I workaround it without have to push force or delete the remote and push the local again?

PS.: Merge is not an option.

Idemax
  • 2,712
  • 6
  • 33
  • 66
  • when you say _after rebase develop into feature_xyz_, I don't think it's clear which branch was rebased **onto** which branch. – eftshift0 Jun 13 '19 at 15:56
  • @eftshift0 sorry for the typo, few free to edit the question... – Idemax Jun 13 '19 at 21:42
  • Why is merging not an option? Rebasing branches that have been pushed before is a bad idea, as it will, by definition, require a force push afterwards. The only way for a pull request to be a fast forward merge of `feature_xyz` into `develop` is if you first merged `develop` into `feature_xyz` and pushed that as your pull request branch. There's no other way, by the definition of what fast-forward means. – joanis Jun 18 '19 at 13:11
  • If this helps, you can think of the `feature_xyz` branch as the staging area for the pull request: it should be at the commit that you want `develop` to point to when the pull request is accepted. By the time the pull request is accepted, the branches will have been merged, one way or another. The place to stage that merge is `feature_xyz`. – joanis Jun 18 '19 at 14:25

1 Answers1

0

I think what you need to do is not a rebase, but rather a merge.

You should merge develop into feature_xyz in your sandbox and push the updated feature_xyz branch.

git checkout feature_xyz
git merge develop
# test the merged results and commit any required fixes
git push

Then, the pull request will indeed be a fast-forward merge as required.

You should ideally not rebase branches that have been pushed. Rebase is best reserved for private branches that still exist only in your sandbox.

joanis
  • 10,635
  • 14
  • 30
  • 40