skip to Main Content

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


  1. Step-by-Step Instructions :

    1. Fetch the Latest Changes from the Remote Repository
      Open IntelliJ IDEA.

    Navigate to VCS > Git > Fetch to fetch the latest changes from the remote repository.

    1. Checkout Your Feature Branch
      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.

    1. 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.

    2. 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.

    1. Continue the Rebase :

    Once all conflicts are resolved, continue the rebase process.
    go to VCS > Git > Rebase, then select Continue Rebase.

    1. Push the Rebased Feature Branch :

    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.

    Login or Signup to reply.
  2. It is recommended to use the Pull Request Merge Conflict Extension to resolve the merge conflicts on the pull request:

    1. Install the Pull Request Merge Conflict Extension to your Azure DevOps organization/collection.

    2. After you commit and push changes to the remote feature branch in Azure DevOps, create a PR (Pull Request) to merge the changes from feature to main.

    3. If certain files had been modified on both sides (feature and main), 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.

      enter image description here

    4. Go the Conflicts tab to manually resolve the conflicts in each file.

      • If you want to retain the updates only from feature branch, select the option "Keep Whole Source (left) File".
      • If you want to retain the updates only from main branch, select the option "Keep Whole Target (right) File".
      • If you want to retain certain updates from both sides, you can manually adjust the conflicted contents, and then click "Submit Merge" to submit the adjusted contents.

      enter image description here

    5. 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.

      enter image description here


    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search