Skip to content
Advertisement

Cannot pull origin dev due to unrelated conflict in Git

I pull a branch (let’s say issue-100) from origin for review and after review I switched to local dev branch without modifying this issue-100 branch. There are some conflicts with this branch, but I did not touch it and just create a new branch after pulling dev branch from origin. But, interestingly, Git gives “Automatic merge failed; fix conflicts and then commit the result.” messages. I just followed these steps:

git checkout dev
git pull origin dev
--> gives error, then I abort merging in IntelliJ

git branch 
git branch -D issue-100
git checkout dev
git pull origin dev
--> gives error, then I abort merging in IntelliJ

So, I did not push issue-100 to origin, but it gives error. How should I fix this problem?

Advertisement

Answer

Conflicts are showing up because of this discrepancy between your local dev and remote dev. If local dev is supposed to be just like remote dev, you should put the branch right there:

git checkout dev
git reset --hard origin/dev # before running this, make sure there are no pending changes laying aroind your working tree as they would be lost

Now local dev and remote dev are exactly the same (content and history). Everything should be back to normal.

There’s this question in my head about why people should not use a local copy of a shared remote branch, but it is waaaaay broader than your question in point and I happen to hold an opinion that is against common wisdom (I think people should not keep a local copy of a remote shared branch but….. that’s just my opinion).

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement