Search code examples
gitgit-rebasefeature-branch

git rebase of feature branches which have been shared


We would like to use rebasing as our standard way of 'merging' our code. We also use fairly short-lived feature branches ( less than 2 weeks) which we push to a central repository via an automated integration manager (each developer has their own personal repositry, and changes are pushed there first and only pushed to the central repository if the build and tests are successful)

When I tried to rebase I got a message saying branches had diverged, and couldn't push to my personal repository until I had first pulled from it and merged in the changes, even though the changes are the same as the ones I had just rebased.

Is there something I should be doing to avoid this? Or is this a consequence of the fact that i have already pushed this feature branch? Can I just replace the branch with my rebased version?

Is there a recommended workflow in this situation?


Solution

  • If no one else has used your commits (i.e. not merged them into anything else, nor started a branch based on them), then you can just replace the branch on the remote (via push --force). Make 100% sure no one else has done anything with the old commits, though, because otherwise they'll run into merge issues of their own.

    If someone else has used the old commits, then you shouldn't rebase them, period.