What exactly does git status say?
The answer determines the action family. Do not mix several repairs at once.
Git field toolbox
Diagnose a repository, choose a workflow and act with the right level of caution. Built for real work situations.
Keyboard: Left/Right arrows, Home and End.
Anti-panic protocol
Git often preserves more exits than expected. Start with readable, reversible actions before deletion or rewriting.
Confirm repository, branch and affected files. Do not repair anything yet.
git rev-parse --show-toplevel
git status --short --branchThe full status message says whether Git awaits a merge, rebase, cherry-pick or revert.
git statusFetch updates your remote view without touching the working branch.
git fetch --all --prune
git branch -vvThe graph shows divergence; the reflog recovers local HEAD movements.
git log --oneline --decorate --graph --all -20
git reflog --date=local -20Before rewriting, name the current commit. A branch copies nothing: it creates a marker.
git branch rescue/before-repairgit status say?The answer determines the action family. Do not mix several repairs at once.
Resolve, stage and continue. If the context is wrong, use the matching abort.
git merge --abort
git rebase --abort
git cherry-pick --abort
git revert --abortPreserve untracked files too, then verify that the working tree is clean.
git stash push -u -m "rescue before diagnosis"Find the still-visible hash, inspect it, then create a recovery branch.
git reflog
git show <hash>
git switch -c rescue/recovered-commit <hash>On a shared branch, revert communicates the undo without moving teammates.
git revert <hash>Soft reset places changes back in the index so you can rebuild the commit.
git branch rescue/before-reset
git reset --soft HEAD~1Open each file, remove markers, test, stage, then continue the operation named by status.
git diff --name-only --diff-filter=U
git add <resolved-file>
git statusOperational atlas
Search an intention, command or symptom. Risk describes the reach of an action, not its syntax.
50 recipes found
git init -b mainCreates the .git directory and starts directly on main.
git clone <repository-url>Downloads history, configures origin and creates a working tree.
git status --short --branchShows branch, ahead/behind state, staged, modified and untracked files.
git log --oneline --decorate --graph --allDraws condensed history with branch and tag references.
git diffCompares the working tree with the index before git add.
git diff --stagedShows exactly what the next commit would contain.
git show <hash-or-reference>Shows metadata and the patch for a commit, tag or HEAD.
git branch --verbose --verboseLists the current branch, latest commit and tracked remote branch.
git remote -vShows addresses used to fetch and push commits.
git rev-parse --show-toplevelReveals the root directory when the terminal is inside a subdirectory.
git blame -L 20,40 -- src/app.jsLinks every line in the range to its latest commit so you can recover context.
git reflog --date=localLists local HEAD movements, including after reset or rebase.
git merge-base main feature/paymentReturns the commit where two branches diverged.
git add src/app.jsPrepares the current version of this file for the next commit.
git add --patchInteractively selects hunks so each commit remains coherent.
git restore --staged src/app.jsTakes the file out of the next commit while preserving its changes.
git restore src/app.jsRestores the file to the state recorded in the index.
git commit -m "Add cart validation"Records index contents with an intent-oriented message.
git commit --amend --no-editReplaces the latest commit with currently staged content.
git switch -c feature/paymentCreates a branch at the current commit and moves HEAD to it.
git switch mainMoves HEAD to the requested branch and updates the working tree.
git branch -m old-name new-nameChanges the local name without changing commits.
git branch -d feature/paymentDeletes the local reference only when Git considers it integrated.
git stash push -u -m "WIP cart"Stores tracked and untracked files, then cleans the working tree.
git stash listShows available stashes and their stash@{n} references.
git stash show --patch stash@{0}Shows the stored patch before you decide to reapply it.
git stash popReapplies the stash, then removes it from the list if successful.
git fetch --all --pruneDownloads remote references and prunes references deleted on the server.
git pull --ff-onlyMoves the branch only when local commits have not created divergence.
git pull --rebaseFetches the remote and places local commits on top.
git push -u origin feature/paymentSends the branch and configures tracking for later push and pull.
git push --force-with-lease origin feature/paymentForces only when the remote branch has not changed since your last fetch.
git merge --no-ff feature/paymentCreates a merge commit even when a fast-forward is possible.
git merge --abortAttempts to return to the state before the interrupted merge.
git rebase origin/mainReplays current-branch commits on top of origin/main.
git add <resolved-files>
git rebase --continueRecords conflict resolution and proceeds to the next commit.
git rebase --abortReturns the branch to its state before the rebase started.
git rebase -i HEAD~4Allows reordering, squashing, rewording or dropping the latest four commits.
git cherry-pick <hash>Copies a commit change onto the current branch with a new hash.
git revert <hash>Creates a new commit applying the inverse without erasing history.
git tag -a v1.4.0 -m "Release 1.4.0"Creates a dated, documented annotated tag at the current commit.
git push origin v1.4.0Sends only this tag to the remote repository.
git worktree add ../hotfix -b hotfix/login origin/mainCreates a branch and another working tree without cloning again.
git worktree remove ../hotfixRemoves the linked working tree after checking it is clean.
git bisect start
git bisect bad
git bisect good <known-good-hash>Starts a binary search between a broken state and a known healthy state.
git bisect good
# or
git bisect badHalves the search area after each manual or automated test.
git bisect resetEnds bisect and returns to the starting branch or commit.
git clean -ndLists untracked files and directories that would be deleted, without acting.
git clean -fdActually deletes untracked files and directories.
git reset --soft HEAD~1Moves the branch back one commit and keeps every change staged.
Team architecture
No flow is universal. Choose from delivery frequency, CI maturity, review duration and maintained versions, then write the rules in the repository.
One releasable main branch and short branches reviewed through pull requests.
git switch -c feature/payment
git push -u origin feature/payment
git fetch origin && git rebase origin/main
git switch main && git pull --ff-onlyDedicated branches separate development, release preparation and urgent fixes.
git switch develop && git switch -c feature/payment
git switch develop && git merge --no-ff feature/payment
git switch -c release/1.4 develop
git switch main && git merge --no-ff release/1.4Everyone integrates very small changes into an always-healthy trunk.
git switch main && git pull --ff-only
git switch -c task/cvv-validation
git commit -m "Add CVV validation"
git rebase origin/main && git push -u origin task/cvv-validationMental model
Read reset/revert, fetch/pull and working tree/index/commit together: their differences explain most mistakes.
Workstation + repository
Apply these settings deliberately, then let the repository and platform enforce shared rules.
Attributable commits and a consistent branch name from repository creation.
git config --global user.name "First Last"
git config --global user.email "you@example.com"
git config --global init.defaultBranch maingit config --show-origin --get-regexp "user\.(name|email)|init\.defaultBranch"Prevent a plain pull from creating an unexpected merge. Choose a policy with the team.
git config --global pull.rebase true
git config --global rebase.autoStash truegit config --global pull.rebase false
git config --global pull.ff onlyPrune deleted remote branches and reuse a conflict resolution already performed.
git config --global fetch.prune true
git config --global rerere.enabled true
git config --global rerere.autoupdate trueShare local checks instead of relying on the unversioned .git/hooks directory.
mkdir -p .githooks
git config core.hooksPath .githooks
chmod +x .githooks/pre-commitSpeed up inspection without hiding destructive operations.
git config --global alias.st "status --short --branch"
git config --global alias.lg "log --graph --decorate --oneline --all"
git config --global alias.unstage "restore --staged --"Exclude dependencies, generated outputs, local files and secrets before first staging.
node_modules/
dist/
.env*
!.env.example
.DS_Store
*.loggit check-ignore -v .env.localLet the platform verify the cryptographic origin of sensitive commits and tags.
git config --global gpg.format ssh
git config --global user.signingkey ~/.ssh/id_ed25519.pub
git config --global commit.gpgsign true
git config --global tag.gpgsign truegit log --show-signature -1Enforce critical rules on the platform where they apply to the entire team.
Origin information explains why a local value can override a global setting.
git config --show-origin --list
git status --short --branch
git remote -v
git branch -vv