Search code examples
gitbitbucketrebasegit-pull

After merge to master, rebase with master giving conflicts for all files merged to master


Case

A new branch created for given requirement

  • Adding changes as per requirement in the branch and
    • Below commands executed every time we commit
      • git add .
      • git commit -m "comment" (committing changes to branch)
      • git pull --rebase origin master (rebase branch with master)
      • git fetch
      • git push -f origin <branch_name>
  • Finally raised a pull request
  • Once approved merged either normal or squashed-way

Problem

Now here, conflicts come every time:

  • After merge to master, when again on same branch running

    • git pull --rebase origin master (rebase branch with master)
    • Then it’s showing conflicts in all the files where changes were done and
    • It’s not getting resolved in one go and
    • Need to make the changes again and again in the files for the count of commits and
    • Then only rebase is getting successful

How to resolve this

Please advice how to avoid this and any change required in approach?


Solution

  • Problem

    After merge to master, when again on same branch running

    • git pull --rebase origin master (rebase branch with master)
    • Then it’s showing conflicts in all the files where changes were done and
    • It’s not getting resolved in one go and
    • Need to make the changes again and again in the files for the count of commits and
    • Then only rebase is getting successful

    Solution: After multiple tries, found below approach solving this ->

    After merge to master, if we need to add more changes in same branch

    Then i tried below steps and above problem not appeared again ->

    1. After merge to master, add more changes in same branch
    2. git add .
    3. git commit
    4. Now instead of git pull --rebase origin master, execute git pull origin master
    5. git fetch
    6. Now, if we execute git pull --rebase origin master then above stated problem will not arise
    7. git push