Reputation: 1063
Newly transitioned from svn to the world of GIT.
I have my master branch: A(initial commit) - B - C - D - E
My feature branch: A(initial commit) - B - Z
I want to rebase my feature branch to master such that: A B C D E Z
How could this be possible? I try to checkout to feature branch and do git rebase master, but apparently it gives me lot conflicts and newly added files of feature getting deleted. I understand that it is rebasing like A - B - Z - C - D - E
Upvotes: 1
Views: 72
Reputation: 11688
This will do exactly what you need, assuming your feature branch was created from master:
git checkout feature
git rebase master
# fix possible conflicts
git checkout master
git merge feature
Firstly, git rebase master
on your feature branch will get Z
and move it to a temporary space. Then bring C
, D
and E
to feature
and finally apply Z
from the temporary area on top of E
.
Resulting in A B C D E Z
At this point, if there is any conflicts you could simply run git mergetool
, solve the conflicts and then git rebase --continue
.
If you run into any issues while fixing conflicts you can cancel, run git rebase --abort
and try again.
After this, the subsequent merge
back to master will be a fast-forward
(no conflicts).
I think this is a good approach because you can keep your feature branch up-to-date with master with your new code always on top of it and you can solve any potential conflicts directly on your feature branch.
Also the merges to back master are always clean and you can create a merge commit by using git merge feature --no-ff
.
Just as a note, this approach has been working for me for a long time. I use kdiff3
as mergetool
.
Upvotes: 1
Reputation: 1063
Following saved my day (thanks to comment from @mrek. His advice gave the direction):
git checkout featurebranch
git rebase --onto masterbranch featurebranch^
(^ denotes parent commit of featurebranch referenced with featurebranch^)
For more information: git rebase --onto explained
Upvotes: 1