Step-by-step solutions for the most common Git problems — with copy-paste commands
This happens when you checkout a commit hash, tag, or remote branch directly instead of a local branch. Any commits you make here are "floating" and can be lost.
git log --oneline -5git checkout maingit checkout -b my-recovery-branchgit checkout main) rather than commit hashes to avoid detached HEAD.There are two safe ways to undo a commit depending on whether you want to keep your changes.
git reset --soft HEAD~1git reset HEAD~1git reset --hard HEAD~1--hard permanently deletes your uncommitted changes. There is no undo. Use --soft unless you are certain.git revert HEAD instead — it creates a new commit that undoes the last one without rewriting history.Git couldn't automatically merge two branches because the same lines were changed differently in each.
git statusgit add src/app.jsgit commitgit mergetool to open a visual diff tool, or use VS Code's built-in merge editor for a cleaner experience.A rebase in progress with conflicts can be safely aborted to restore your branch to its pre-rebase state.
git rebase --abortgit add .git rebase --continuegit rebase --skipgit rebase --abort is always safe — it fully restores your branch to its original state before the rebase started.Both undo changes, but they work very differently and are suited to different situations.
git revert when the commit has already been pushed to a shared branch. It creates a new commit that undoes the changes — safe for team repos:git revert HEADgit revert <commit-hash>git reset only on local, unpushed commits. It rewrites history:git reset --soft HEAD~1git reset on commits that others have already pulled. It rewrites history and will cause conflicts for your teammates.Someone else pushed to the remote branch since your last pull. You need to integrate their changes first.
git pull origin maingit pull --rebase origin maingit push origin maingit push --force on shared branches. It overwrites others' work. Only use force-push on your own feature branches.Git can't verify the SSL certificate of the remote server. Common on corporate networks with custom CA certificates or misconfigured Git installs.
git config --global http.sslCAInfo /path/to/ca-bundle.crtgit config --global http.sslVerify falseWindows uses CRLF line endings, Unix/Mac use LF. Git is warning you about automatic conversion. This can cause noisy diffs and cross-platform issues.
git config --global core.autocrlf truegit config --global core.autocrlf input.gitattributes file to your repo root:* text=auto eol=lf.gitattributes file overrides individual developer settings and is the most reliable way to enforce consistent line endings across a team.Files Git doesn't know about yet. You either want to track them, ignore them, or remove them.
git add <filename>.gitignore:echo "node_modules/" >> .gitignoregit clean -ngit clean -fdgit clean -fd permanently deletes files. Always run git clean -n first to preview what will be removed.Your stashed changes conflict with the current state of the working tree. Git can't apply the stash cleanly.
git stash listgit stash apply stash@{0}git add src/app.jsgit stash drop stash@{0}git stash apply instead of git stash pop when you're unsure — it keeps the stash entry until you manually drop it, so you can retry if something goes wrong.The Fix Git Errors tool provides quick, copy-paste solutions for the most common Git problems developers encounter. Each error includes the exact error message, a clear explanation of why it happens, and step-by-step commands to fix it. Whether you're stuck in a detached HEAD, need to undo a commit, or are resolving a merge conflict, this guide has you covered.
Detached HEAD and "undo last commit" are urgent. Stop, don't push or force anything. Use the recovery steps to safely get back to a clean state.
Conflicts are normal. Use the step-by-step conflict resolution process. Know when to abort (git rebase --abort) vs continue (git rebase --continue).
Push rejected means someone else pushed first. Pull/merge before pushing again. Never --force on shared branches.
Untracked files, stash conflicts, line ending issues — these are local cleanup tasks. Use git clean carefully (preview first).
git reset moves the branch pointer backward, effectively deleting commits from the branch history. It rewrites history and should only be used on commits that have not been pushed. git revert creates a new commit that undoes the changes of a previous commit — it's safe for shared branches because it doesn't rewrite history. Rule: pushed = revert. Local-only = reset.
Don't panic — the commit isn't immediately deleted. Use git reflog to see the HEAD movement history. Find the commit hash before the reset, then either git reset --hard <hash> to go back or git checkout -b recovery <hash> to create a new branch at that point. git reflog entries typically expire after 90 days.
--soft undoes the commit but keeps all changes staged — use when you want to recommit with a different message or additional changes. --mixed (default) undoes the commit and unstages changes but keeps the files modified — use when you want to re-stage selectively. --hard discards both commit and all uncommitted changes — use only when you're certain you want to throw away work.
Yes, completely free with no sign-up required.