We use git and have a master branch and developer branches. I need to add a new feature and then rebase the commits to master, then push master to CI server.
The problem
The general answer that has already been given -- to use git push -f origin myNewFeature
when pushing rebased changes -- is a good starting place. I'm writing this answer to address the edit about whether it will break your workflow.
If we assume that you're going to be using git pull --rebase ...
(or some variation on that) followed by a force-push to the remote branch, then the thing that breaks the workflow in your example is developer2 is merging myNewFeature
into hisNewFeature
. It makes sense to be able to rebase your own feature branch as long as nobody else is working on that branch, so you need rules to demarcate branch territory.
You can get around this by a) establishing a rule that you only ever merge from master
, or b) creating a collective develop
branch, upon which you base your own myNewFeature
branch, and establish a rule that you only ever merge from develop
. master
will then be reserved only for milestones or releases (or however else you want to set that up), and develop
will be where you push each feature when it's ready to be integrated into other feature branches.
I believe this could be considered a simplified version of the Gitflow workflow.