Resolve GitHub Merge Conflicts |Video upload date:  · Duration: PT4M32S  · Language: EN

Step by step guide to resolve GitHub merge conflicts using command line and merge editors for fast safe integration

Practical git merge conflict resolution for teams and CI pipelines

If your repo had feelings it would probably file restraining orders against merge conflicts. They are inevitable but not invincible. This guide walks through a calm and slightly sarcastic path to fetch changes merge branches and resolve conflicts on the command line or with a merge tool. Follow the steps and avoid becoming the office legend who broke main.

Step 1 Fetch and update your local repo

Always start by getting the latest remote state. This prevents surprises and passive aggressive PR comments.

git fetch origin
git status

git fetch origin updates remote tracking branches. git status confirms your working tree is clean. If you have uncommitted changes stash them or commit them before continuing.

Step 2 Switch to the branch that should receive changes

Checkout the target branch where the merge will land. Typical targets are main or develop.

git checkout target-branch

Replace target-branch with the branch name you actually use. Yes you can type faster but do not make typos here.

Step 3 Merge the source branch

Bring the other branch in. If Git is feeling generous this will be automatic. If not you will be introduced to conflict markers.

git merge source-branch

If the merge completes with a nice quiet message you are lucky and may celebrate quietly. If not you will see conflict messages and changed files listed by git status.

Understanding conflict markers

When Git cannot reconcile the changes it injects conflict markers into the file. They look like this.

<<<<<<< HEAD
...your current code...
=======
...incoming code from source branch...
>>>>>>> source-branch

Your job is to pick, edit, or combine the bits so the file reads like sane human code again.

Step 4 Resolve the conflicts

You have two main options. Fix them manually or use a visual merge tool for mercy.

Manual resolution

  • Open each file listed by git status
  • Remove the conflict markers and edit to produce correct code
  • Save and run tests locally if you can

Use a merge tool

If you prefer less keyboard therapy use a GUI tool. VS Code merge editor Meld and many IDEs will show both sides and let you choose hunks. Configure a graphical tool if you like pretty diffs.

Step 5 Stage commit and push

Once the files read correctly stage them and finish the merge.

git add path/to/file1 path/to/file2
git commit
git push origin target-branch

Git commit will complete the merge commit. Use a clear message that explains what you chose and why. Future you will thank present you or at least whisper forgiveness.

Checklist before pushing

  • Run your test suite locally when possible
  • Enable a graphical merge tool if you need one
  • Write a commit message that documents the conflict resolution
  • Verify continuous integration passes in the PR

Troubleshooting and tips

  • If you accidentally staged bad changes use git reset HEAD path to unstage a file
  • If the merge is a mess and you want to start over run git merge --abort while the merge is in progress
  • Prefer small frequent merges to huge scary ones that happen after a long vacation

Merge conflicts are not personal attacks. They are just code trying to be important. Keep calm fetch often and make your commit messages good enough for future archaeologists. If you must, blame the test that caught the problem and move on.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.