Skip to content

Instantly share code, notes, and snippets.

@ismusidhu
Created July 25, 2026 06:02
Show Gist options
  • Select an option

  • Save ismusidhu/516c9fbd0025d78d96ca631c18f5c7d2 to your computer and use it in GitHub Desktop.

Select an option

Save ismusidhu/516c9fbd0025d78d96ca631c18f5c7d2 to your computer and use it in GitHub Desktop.
Team Git Conflict & Workflow Guide

πŸ“– Git Conflict & Workflow FAQ

Q1: How do I avoid merge conflicts before starting work?

The Rule: Always sync your branch before you write a single line of new code.

  • Visual Studio (GUI): Open Git Changes tab $\rightarrow$ click Fetch (down arrow) $\rightarrow$ select main $\rightarrow$ click Pull.
  • VS Code: Click Source Control icon $\rightarrow$ ... (ellipsis) $\rightarrow$ Pull, Push $\rightarrow$ Pull from... $\rightarrow$ select origin/main.
  • Terminal (3rd Way):
git checkout main
git pull origin main
git checkout -b feature/your-new-branch

πŸŽ₯ Video Guide: How to Sync Main Branch Before Starting Work


Q2: What if I forgot Q1, already edited files, and NOW ran into a conflict?

Scenario: You spent 3 hours writing code, tried to pull/merge main, and now Git is screaming at you with a massive wall of conflicts because your local branch was outdated.

Don't panic! Your work is not lost. You have two clean options depending on whether you've committed your changes yet:

Option A: You haven't committed your local changes yet (The "Stash" Trick)

This temporarily hides your new code in a safe box, updates your branch, and places your changes back on top.

  • Visual Studio:
  1. In Git Changes, click Stash All (or the stash icon).
  2. Click Sync / Pull to get the latest main updates cleanly.
  3. Under the Stashes section at the bottom, right-click your stash $\rightarrow$ Apply Stash.
  • VS Code:
  1. In Source Control, click ... (ellipsis) $\rightarrow$ Stash $\rightarrow$ Stash (Include Untracked).
  2. Click Sync / Pull to bring your branch up to date.
  3. Click ... (ellipsis) $\rightarrow$ Stash $\rightarrow$ Pop Stash.
  • Terminal (3rd Way):
git stash
git pull origin main
git stash pop

Option B: You already committed your local changes

If your changes are already committed locally, you need to pull the updated main directly into your feature branch to trigger the merge resolution.

  • Visual Studio: Go to Git menu $\rightarrow$ Manage Branches $\rightarrow$ right-click origin/main $\rightarrow$ select Merge Into Current Branch.
  • VS Code: Open Command Palette (Ctrl+Shift+P) $\rightarrow$ type Git: Merge Branch $\rightarrow$ select origin/main.
  • Terminal (3rd Way):
git fetch origin
git merge origin/main

(Once triggered, move to Q3 to resolve the conflict inline).

πŸŽ₯ Video Guide: How to use Git Stash to save your work and fix conflicts



Q3: What should I do when a Merge Conflict appears?

A conflict just means Git sees two different edits on the same line and needs a human decision.

  • Visual Studio (GUI):
  1. Double-click the file under Unmerged Changes.
  2. The Merge Window shows Incoming (Left), Current (Right), and Result (Bottom).
  3. Check the boxes next to the lines you want to keep.
  4. Click Accept Merge.
  • VS Code:
  1. Click the file marked with a red status in Source Control.
  2. Click Resolve in Merge Editor at the bottom right.
  3. Compare changes and check the boxes for the code to keep.
  4. Click Complete Merge.
  • Terminal + P4Merge (3rd Way):
# Launches P4Merge tool
git mergetool

Resolve the lines in the bottom pane of P4Merge, save, close, and then run:

git add .
git commit -m "Resolved merge conflict"

πŸŽ₯ Video Guide: Resolving Git Merge Conflicts in VS Code & Visual Studio


Q4: What if I mess up mid-conflict and want a "Do-Over"?

If the merge gets messy or you picked the wrong lines, you can safely trigger an instant reset to return to your exact pre-merge state.

  • Visual Studio: Git menu $\rightarrow$ Manage Branches $\rightarrow$ right-click merge status $\rightarrow$ Abort Merge.
  • VS Code: Open Command Palette (Ctrl+Shift+P) $\rightarrow$ type Git: Abort Merge.
  • Terminal (3rd Way):
git merge --abort

πŸŽ₯ Video Guide: How to Abort a Bad Git Merge


Q5: What is git cherry-pick, and when is it simpler than a merge?

What it is: Instead of merging 50 commits from another branch, cherry-pick lets you grab one specific commit and apply it to your current branch.

When to use it: A team member fixed a bug on main, and you need only that fix in your feature branch immediately without pulling down unreleased code.

  • Visual Studio: Open Git Repository Window $\rightarrow$ right-click the target commit in history $\rightarrow$ Cherry-Pick.
  • VS Code: In Source Control (with GitLens extension), view commit history $\rightarrow$ right-click target commit $\rightarrow$ Cherry Pick Commit.
  • Terminal (3rd Way):
# Get the commit hash (e.g. a1b2c3d)
git cherry-pick a1b2c3d

πŸŽ₯ Video Guide: Git Cherry Pick Explained with Visuals

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment