My business case: we are 3 testers working on a common code base stored in the Main
branch.
Last week, I started working on a new test by creating a feature branch off Main
.
However before I could create a PR, the other 2 testers pushed their changes and got merged into the Main
branch.
Now my problem is that my feature branch is not in sync with Main
branch anymore. How do I pull the latest changes into feature from Main
?
Git fetch
or Git pull
didn’t update my feature branch, it only updated my local main branch, but my local feature branch is still not updated with latest changes from main.
How do I rebase my local feature branch with latest copy of main branch in INTELLIJ IDE Ultimate.
I get confused when selecting ACCEPT MY CHANGE or ACCEPT THEIR CHANGE.
I messed up my branch while doing that ….
How do I update my feature branch from latest copy of master without losing my local changes.
Please guide me
2
Answers
Step-by-Step Instructions :
Open IntelliJ IDEA.
Navigate to
VCS > Git > Fetch
to fetch the latest changes from the remote repository.In the bottom-right corner of IntelliJ IDEA, click on the branch name to open the Branches popup.
Select your feature branch and choose Checkout.
Rebase Your Feature Branch onto the Latest Main Branch
Navigate to
VCS > Git > Rebase
.Select Rebase Current Branch on….
In the dialog that appears, choose the main branch (e.g., origin/main) as the target branch and click Rebase.
Resolve Conflicts (If there are conflicts)
For each conflict, use the diff viewer provided by IntelliJ IDEA:
Accept Yours (Accept My Change): Keeps your changes and discards the incoming changes from the main branch.
Accept Theirs (Accept Their Change): Keeps the changes from the main branch and discards your changes.
Merge: Allows you to manually merge the changes by editing the file.
After resolving each conflict, mark the file as resolved by clicking the Mark as Resolved button in the upper-right corner of the diff viewer.
Once all conflicts are resolved, continue the rebase process.
go to
VCS > Git > Rebase
, then select Continue Rebase.After successfully rebasing and resolving conflicts, push your feature branch to the remote repository.
Go to
VCS > Git > Push
.In the Push dialog, make sure to push your feature branch.
Use the
--force-with-lease
option to ensure you don’t overwrite any changes that may have been pushed by others.It is recommended to use the Pull Request Merge Conflict Extension to resolve the merge conflicts on the pull request:
Install the Pull Request Merge Conflict Extension to your Azure DevOps organization/collection.
After you commit and push changes to the remote
feature
branch in Azure DevOps, create a PR (Pull Request) to merge the changes fromfeature
tomain
.If certain files had been modified on both sides (
feature
andmain
), on the Overview of the PR, you can see the "merge conflicts
" error reported and the list of the conflicted files. In this situation, you cannot complete the PR merge.Go the Conflicts tab to manually resolve the conflicts in each file.
feature
branch, select the option "Keep Whole Source (left) File
".main
branch, select the option "Keep Whole Target (right) File
".Submit Merge
" to submit the adjusted contents.After resolving conflicts in all the files, turn to Overview, you can see the "
merge conflicts
" error disappeared, and the message "No merge conflicts
" displayed. At this time, you can complete the PR merge as normal.