Skip to main content

๐Ÿงฉ Resolving Complex Git Merge Conflicts Locally

โš ๏ธ Problem

When merging a pull request on GitHub, you may encounter:
โ€œThese conflicts are too complex to resolve in the web editor.โ€
This usually means:
  • Large structural differences in files
  • Binary file conflicts
  • Changes scattered across a file
  • Multiple developers editing the same areas

๐Ÿ› ๏ธ Solution: Use Git Locally to Resolve

โœ… Step 1: Clone the Repository (if not done already)

git clone https://github.com/your-username/your-repo.git
cd your-repo

๐Ÿ” Step 2: Checkout the Base Branch (e.g., main)

git checkout main
git pull origin main

๐Ÿ”€ Step 3: Merge the Source Branch (e.g., feature-branch)

git merge feature-branch
If there are conflicts, Git will output which files are conflicting.

๐Ÿงน Step 4: Resolve Conflicts Manually

Open the conflicted files in your editor. Youโ€™ll see conflict markers like this:
<<<<<<< HEAD
// Your changes in main branch
=======
 // Their changes from feature-branch
>>>>>>> feature-branch
๐Ÿ“ Manually edit the file to keep the correct/combined version. Then save the file.

โœ… Step 5: Mark the File as Resolved

git add path/to/conflicted-file
Do this for each conflicted file you resolve.

๐Ÿ’พ Step 6: Commit the Merge

git commit
Git will open the default merge message. You can leave it as-is or edit it.

๐Ÿš€ Step 7: Push the Changes to GitHub

git push origin main
Now the PR should be marked as merged (or you can close the PR if youโ€™ve pushed directly to main).

๐Ÿงฐ Tips

  • Use git status to see unresolved files.
  • Use GUI tools like VS Code, Sourcetree, or GitKraken if you prefer visual merge tools.
  • For large repos, make a backup branch before merging:
    git checkout -b backup-main-before-merge