shlogg · Early preview
Ayush Porwal @ayush-porwal

Resolving Merge Conflicts With Git: A Step-by-Step Guide

Stuck with merge conflicts? Delete last 2 commits & re-sync with main: `git reset --hard HEAD~2` then `git merge main`. Push changes with `--force` or `--force-with-lease` to avoid overwriting others' work.

Today morning, as any other work day, I logged in to my GitHub account to check the status of my open pull requests. I saw I had some merge conflicts and I needed to sync with the main.
I found myself in a situation where I needed to delete the last two commits and re-sync with the main.
First of all, I switched to main and pulled the latest changes

git pull origin main

    
    

    
    




Then I checked back to my working branch. First of all, I need to delete the last two commits. We have two options:

: '
this will take you to the commit before the last two commits and then keep the...