Git Emergency
I'm stuck in a merge conflict
Severity Minor
What just happened
Two branches changed the same lines. Git stopped the merge (or rebase, or pull) and asks you to choose. Nothing is lost: both versions are in the file.
Potential risks
- Committing files that still contain conflict markers breaks the build.
- “Resolving” by deleting the other side silently throws away a colleague's work.
Before you run anything
- Between <<<<<<< and ======= is your version; between ======= and >>>>>>> is theirs.
- When unsure, ask the author of the other change.
Recovery steps
- 1
See which files are in conflict
Look for “both modified”.
Safe$ git status$ git diff --name-only --diff-filter=U - 2
Panic button: cancel everything
Back to the state before the merge or rebase started.
Safe$ git merge --abort# or, during a rebase:$ git rebase --abort - 3
Take one side for a whole file
Only when you are sure one version is right. During a rebase, “ours” and “theirs” are swapped.
Caution$ git checkout --ours path/to/file# or$ git checkout --theirs path/to/file - 4
Mark as resolved and finish
After editing the files and removing every marker.
Safe$ git add path/to/file$ git commit# or, during a rebase:$ git rebase --continue
These procedures are provided for information only. Read each command and adapt it to your situation before running it. Disclaimer
Other disasters
🪓 I deleted my branch🚨 I pushed directly to main💥 I ran git reset --hard🧨 I overwrote a colleague's commits🔑 I pushed my .env file to GitHub🔀 I made a bad merge👻 I lost uncommitted changes🎯 I committed on the wrong branch🎈 I'm in “detached HEAD” state🚫 My push is rejected (non-fast-forward)🌀 My rebase went wrong🐘 GitHub rejects a file over 100 MB🥸 I committed with the wrong name or email🗑️ I deleted a file and committed it⏪ I want to undo my last commit✏️ I amended a commit that was already pushed🧹 Too many messy commits to clean up📮 I pushed to the wrong branch🧭 I rebased onto the wrong branch🔁 I need back the changes I reverted📦 git stash pop gave me a conflict🙈 I committed a file that should be ignored🔠 Git doesn't see my file rename (upper/lower case)🧨 I ran git clean -fd by mistake🩻 My repository is corrupted🙃 I forgot to pull before pushing👯 Duplicated lines of code after a merge➖ I added a file I didn't want to (git add)✏️ I made a typo in a commit message✂️ My commit does too many things🧺 I lost a stash (drop, clear or pop gone wrong)🫥 I pulled and my code disappeared🍒 I cherry-picked the wrong commit☁️ I deleted a branch on GitHub / GitLab👥 I pushed with the wrong GitHub account🚚 The repository was renamed or moved🏷️ I tagged the wrong commit🌊 Git says every file is modified, but I changed nothing📦 I committed node_modules (or a build folder)📂 I ran git init in the wrong folder🧨 My pull request has conflicts⏳ My pull request is behind main📝 I have to apply review changes to my PR🧳 My PR shows commits that aren't mine🎯 I opened my PR against the wrong branch🚨 A merged PR broke main🚪 I closed my PR (or deleted its branch) by mistake🔴 The checks of my PR are failing🐘 My PR is too big to review🍴 My fork is behind the original repository