I am using bitbucket and am running into problems using the rebase feature of git. In short I need to reapply changes I already applied each time I rebase. I have recreated the problem using the steps below. Its a simplified version but the outcome was the same.
contributors.txt
to master
, commits and pushes. Now master
has a contributors.txt
file. The contents of the file is
Developer A
branch-a
from master
.branch-b
from master
.branch-a
so it looks like.
Developer A
Developer A2
branch-b
so it looks like
Developer A
Developer B
branch-a
branch-b
.branch-a
with master
.branch-b
and does git rebase master
Developer A
Developer A2
Developer B
git add
to add the fixed conflict and runs git rebase --continue
. All goes well.branch-b
since now the local and remote branch-b
has diverged they need to be merged. (Needs to set-upstream before pull)branch-b
has the changes from master and can be pushed to remote.branch-b
to remote. using git push origin branch-b
. All goes well.branch-b
and commits.git checkout master
git pull
(master is up to date since it has not changed since last pull i.e. Step 9)git checkout branch-b
git rebase master
git rebase master
is executed, git asks developer B to resolve the same conflicts all over again. Why does this happen? Shouldn't the already applied changes be known and not asked to be applied again?I think I can use merge instead of rebase to overcome this problem. But it seems like I am using rebase incorrectly. Please let me know what I am doing wrong
After step 13, you should be able to do a git push origin branch-b --force
. This will push the rebased version to branch-b
to your remote, and because it's been rebased on top of master, you should then be able to merge with master without any issue.
The issue with the previous method is that after rebasing on top of master, you're just adding the merge commit to origin/branch-b which hasn't been rebased on top of master so it's still diverged. If you do a force push, then it just replaces the remote branch with your rebased branch.