Search code examples
gitvisual-studiogit-merge-conflict

How to resolve GIT conflict if I forgot to push the commits and created a feature branch from my local develop branch?


I'm looking for an easy way to resolve my current git conflict.

This it how it happened:

  1. local commits (5) created on my develop branch (without pushing them)
  2. feature branch created from my local develop branch
  3. feature branch development finished, commits have been pushed
  4. PULL request from feature branch to develop merged
  5. Now I checked out my local develop branch and when I tried to sync I saw that there are already incoming and outgoing commits too, now I realized that I forgot to push them earlier and guessed I'm having a trouble...
  6. (tried to sync but not surprisingly it has a lot of conflicts)

I hope it's understandable and someone could help me, please. Thank you!


Solution

  • If you have not made any new commits on your local develop branch since you have created the feature branch (feature branch that was pushed, and then merged to the remote origin/develop branch), you could simply:

    • fetch from origin
    • reset your current develop branch to origin/develop

    (I would save, for the above scenario or the one below, your local repository in a duplicate folder, just in case something foes wrong)


    That would work since origin/develop does include your local develop+feature work, merged through the pull request to origin/develop.

    If you had done commits on develop since the creation of feature, you can rebase those new commits on top of origin/develop

    git fetch origin
    git branch tmp origin/develop
    git rebase --onto tmp $(git merge-base feature develop) develop
    git branch -f develop tmp
    git switch develop