// Git Emergency
What did you break?
Pick your disaster. We explain what happened, how bad it is, and how to get out of it — safest option first.
Commits & local work
I want to undo my last commit
MinorToo early, wrong files, bad message. Three ways out depending on what you want to keep.
I added a file I didn't want to (git add)
MinorNothing is committed yet: take it out of the index, your changes stay.
I made a typo in a commit message
MinorLast commit, older commit, already pushed or not: each case has its fix.
My commit does too many things
MinorSplit it into several clean commits before pushing.
I committed on the wrong branch
MinorClassic. Move the commits where they belong.
I committed with the wrong name or email
MinorYour personal email on the work repo, or your work email on your side project.
Too many messy commits to clean up
Minor“wip”, “fix”, “fix again”, “ok now”… Turn them into one clean commit before the PR.
I ran git reset --hard
SeriousCommits vanished? The reflog has them. Uncommitted changes? It's complicated.
I lost uncommitted changes
AnnoyingCheckout, stash drop, or a clean -fd. Let's dig.
I lost a stash (drop, clear or pop gone wrong)
AnnoyingA dropped stash is a commit nobody points to anymore: it can be found back for a while.
I deleted a file and committed it
MinorThe file is gone from the current version, but Git remembers every version of it.
Branches, merges & rebases
I deleted my branch
Annoyinggit branch -D, or deleted on GitHub. The commits are probably still there.
I'm in “detached HEAD” state
MinorYou checked out a commit or a tag, not a branch. Your new commits float in the void.
I'm stuck in a merge conflict
Minor<<<<<<< everywhere and no idea what to keep. Breathe, it's fixable.
I made a bad merge
AnnoyingWrong branch, botched conflicts, or a merge that broke everything.
Duplicated lines of code after a merge
AnnoyingA function, an import or a whole block appears twice after merging a branch or resolving a conflict.
My rebase went wrong
AnnoyingCommits disappeared, duplicated, or the history is a mess after a rebase.
I rebased onto the wrong branch
AnnoyingYour branch now contains commits from another feature, or is based on develop instead of main.
I need back the changes I reverted
MinorYou reverted a merge, fixed the bug, and now merging the branch again brings nothing.
git stash pop gave me a conflict
MinorThe stash didn't apply cleanly. Good news: it's still there.
I cherry-picked the wrong commit
MinorIn progress: abort. Done: reset if not pushed, revert if pushed.
Push & remote
I pushed directly to main
SeriousNo PR, no review, straight to main. Undo it without rewriting shared history.
I forgot to pull before pushing
MinorPush rejected, an ugly “Merge branch 'main' of…” commit, or hours of work on an outdated version.
My push is rejected (non-fast-forward)
Minor“Updates were rejected because the remote contains work that you do not have locally.”
I amended a commit that was already pushed
AnnoyingNow git push is rejected and Git says your branch has diverged.
I pushed to the wrong branch
AnnoyingYour commits landed on a colleague's branch, or on a branch with a typo in its name.
I overwrote a colleague's commits
CriticalA git push --force wiped someone else's work from the remote.
GitHub rejects a file over 100 MB
Annoying“remote: error: File is 245 MB; this exceeds GitHub's file size limit.”
I pulled and my code disappeared
SeriousAlmost always recoverable: Git refuses to overwrite uncommitted work, and the reflog remembers the rest.
I deleted a branch on GitHub / GitLab
AnnoyingIf anyone still has it locally, push it back. GitHub also offers a “Restore branch” button on the pull request.
I pushed with the wrong GitHub account
MinorTwo accounts (personal / work) on one machine: separate them per folder or per SSH key.
The repository was renamed or moved
MinorPoint your remote to the new address. Nothing else changes.
I tagged the wrong commit
AnnoyingMove the tag locally; if it was pushed (and maybe released), think twice before moving it.
Pull requests
My pull request has conflicts
Annoying“This branch has conflicts that must be resolved”: bring main into your branch and fix them locally.
My pull request is behind main
Minor“This branch is out-of-date with the base branch”: update it, then CI runs again on the real result.
I have to apply review changes to my PR
MinorCommit on the same branch and push: the PR updates itself. Tidy the commits before merge if your team wants it.
The checks of my PR are failing
MinorRead the failing job's logs, reproduce locally, push a fix. Don't merge red.
My PR shows commits that aren't mine
AnnoyingYour branch started from the wrong place (another feature branch, an old main). Move only your commits.
I opened my PR against the wrong branch
MinorChange the base of the PR (Edit button next to the title). No need to close it.
My PR is too big to review
MinorSplit it into several small PRs, each one reviewable on its own (stacked PRs).
My fork is behind the original repository
MinorAdd the original as upstream, update your main, then rebase your PR branch.
I closed my PR (or deleted its branch) by mistake
MinorA closed PR can be reopened; a deleted branch can be restored from the PR page.
A merged PR broke main
SeriousRevert the PR (GitHub has a Revert button), deploy, then fix calmly in a new PR.
Files & repository
I committed a file that should be ignored
Minornode_modules, dist, .DS_Store, logs… Adding it to .gitignore afterwards changes nothing.
Git says every file is modified, but I changed nothing
MinorLine endings (CRLF / LF) or file permissions. Not real changes.
I committed node_modules (or a build folder)
AnnoyingRemove it from Git (not from disk), ignore it, commit. Clean the history only if it's huge.
I ran git init in the wrong folder
AnnoyingDelete the .git folder that was just created (and only that). Your files don't move.
Git doesn't see my file rename (upper/lower case)
MinorHeader.tsx → header.tsx works locally but breaks the build on Linux / in CI.
I ran git clean -fd by mistake
SeriousNew files you had never committed are gone.
My repository is corrupted
Serious“object file is empty”, “bad object”, “loose object is corrupt” after a crash or a full disk.
Security
Golden rule: before any destructive command, create a safety branch with git branch backup/before-fix — it costs nothing.