In Git, I have two branches: master and myFeatureBranch (which I created via IDEA's new branch while I was on master). In the time since I created myFeatureBranch, other team members have committed several changes to master. I would like to bring in those changes, and I am aware that I will have merge conflicts.
My general idea of how to deal with this is:
Intellij IDEA 2016 added some new features including Checkout with Rebase. From their announcement:
The Checkout with Rebase action is useful if you don’t want to waste your time on extra files synchronization and compilation when you do two operations: Checkout and then Rebase.
Sounds like what I'm wanting. I am already on master, so I click on the branch selector at the bottom right of my IDEA window. I navigate to my local branches and choose "Checkout with Rebase".
After doing this, I am told about my merge conflicts. I choose the "Merge" button and resolve them manually.
After I do that, I get a confirmation that my rebase was successful:
And there are no pending changes:
Everything looks like it worked. Now I want to push everything, including my merged classes, to my remote branch. So I go to the menu bar and choose VCS -> Git -> Push. But when I do that, I get an error saying that my push was rejected and that I should merge:
I decided to follow the advice and choose "Merge". However, this brought me right back to the merge conflict.
If I go through with this and then try pushing it again, it is successful, but I wind up with two copies of the merge.
What am I doing incorrectly with this "Checkout with Rebase" and then pushing my merged files?
Also, I don't want to do this from the Terminal. That may be easier for some developers, but I would like to learn how to do it entirely through the IDEA GUI (we have QA and other users who are not as technical as our developers and they have expressed a desire to not have to use the command line, and I'd like to know the best way for them).
IMHO, you've got the same problem if you checkout first your feature branch, then rebase it on the master and want to push to remote.
By rebasing your feature branch, you have modified the commit history, either by use "Checkout with Rebase" or doing this manually. So you can't simply push the new commit tree to remote branch, you've got to push a new commit tree to remote.
In my case, as i usually work alone on feature branch, when i rebase it on master, I use "Force push" option when i want to push my commits on remote branch.
Force push option
In that case, git doesn't try to add new commit (calc by diff) on the top of the remote commit tree but erase the entire tree of the remote branch and replace it with the commits of your local feature branch. Be very careful if other people work with the remote feature branch, don't use this option ! they'll be in big trouble if they want to push after your forced push because git can't compare their commit history and the new history you've just publish and they can't push their commits (they can't).
There certainly a better way to do this when more than one developper work on feature branch but I don't know it.
Hope than it can help
I also have met such problem when I did rebase. A lot of conflicts resolved and there's problem in the end. Of course, merge isn't good solution from my point, because result won't look so great.
Before rebasing, rename your origin branch which you going to rebase, and then after rebase use your old origin branch name. Or simply after rebasing push changes to new origin branch.
Main point to push to different branch, not to the same. That's help me to resolve this problem.
For example,
feature - - - -
/
dev - - - . - - - - - - . - -
Will become to:
update-feature - - - -
/
dev - - - . - - - - - - . - - - - -
And it will be done without any problems.
I hope it helps you :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With