Set global identity
git config --global user.name "[name]"
git config --global user.email "[email]"Online Git cheat sheet with categorized commands for config, init, commit, reset, and branch tasks, plus one-click copy for daily workflows.
Set global identity
git config --global user.name "[name]"
git config --global user.email "[email]"List all config values
git config --listShow a single config value
git config user.nameCreate a Git repository
git initClone an existing repository
git clone [url]Clone a specific branch
git clone -b [branch-name] [url]Check working tree status
git statusShow unstaged changes
git diffShow staged changes
git diff --stagedShow the latest commit details
git show HEADStage all changes
git add .Stage a specific file
git add [file]Unstage a specific file
git restore --staged [file]Discard working tree changes for a file
git restore [file]Commit staged changes
git commit -m "[commit message]"Commit all tracked changes
git commit -am "[commit message]"Amend the last commit without changing message
git commit --amend --no-editAmend the last commit message
git commit --amend -m "[commit message]"List local branches
git branchList local and remote branches
git branch -aCreate a new branch
git branch [branch-name]Switch to a branch
git switch [branch-name]Create and switch to a branch
git switch -c [branch-name]Delete a merged branch
git branch -d [branch-name]Force delete a branch
git branch -D [branch-name]Rename the current branch
git branch -m [new-branch-name]List remotes
git remote -vAdd a remote repository
git remote add origin [url]Change remote URL
git remote set-url origin [url]Remove a remote
git remote remove originFetch updates from remote
git fetch originPull and merge a branch
git pull origin [branch-name]Pull with rebase
git pull --rebase origin [branch-name]Push to a remote branch
git push origin [branch-name]Push and set upstream
git push -u origin [branch-name]Force push with lease protection
git push --force-with-lease origin [branch-name]Show compact commit graph
git log --oneline --graph --decorate --allShow commit history for a file
git log -- [file]Show line authorship for a file
git blame [file]Show reflog history
git reflogCreate a full repository bundle
git bundle create repo.bundle --allVerify a bundle file
git bundle verify repo.bundleClone from a bundle
git clone repo.bundle [dir-name]Pull updates from a bundle
git pull repo.bundle [branch-name]Export current branch as ZIP archive
git archive --format=zip --output=project.zip HEADExport a tag archive
git archive --format=tar.gz --output=release.tar.gz [tag-name]Export a specific subdirectory
git archive --format=zip --output=folder.zip HEAD:[path]List commit notes
git notes listAdd a note to current commit
git notes add -m "[note]"Show notes for a commit
git notes show [commit-hash]Append note content
git notes append -m "[note]" [commit-hash]Remove notes for a commit
git notes remove [commit-hash]Analyze repository history structure
git filter-repo --analyzeRemove a path from history
git filter-repo --path [path] --invert-paths --forceKeep only a path in history
git filter-repo --path [path] --forceReplace sensitive text across history
git filter-repo --replace-text replacements.txt --forceStart bisect session
git bisect startMark current commit as bad
git bisect badMark a commit as good
git bisect good [commit-hash]Reset and end bisect session
git bisect resetCheck repository object integrity
git fsckShow unreachable objects
git fsck --unreachableRun a full repository check
git fsck --fullClean up and compact repository objects
git gc --prune=nowStart background maintenance
git maintenance startRun automatic maintenance
git maintenance run --autoRegister repository for maintenance
git maintenance registerStop background maintenance
git maintenance stopRebase current branch onto target branch
git rebase [branch-name]Continue an in-progress rebase
git rebase --continueSkip the current conflicted commit
git rebase --skipAbort the current rebase
git rebase --abortReplace one object reference with another
git replace [old-object] [new-object]List replace refs
git replace -lEdit a replace object
git replace --edit [object-id]Delete a replace ref
git replace -d [object-id]Enable rerere conflict reuse
git config rerere.enabled trueShow current rerere status
git rerere statusShow rerere conflict diff
git rerere diffForget conflict resolution for a path
git rerere forget [path]Clear all rerere records
git rerere clearConfigure Git Credential Manager
git config --global credential.helper manager-coreConfigure in-memory credential cache
git config --global credential.helper cacheApprove credentials for helper storage
git credential approveFill matching credentials
git credential fillReject matching credentials
git credential rejectInitialize sparse checkout
git sparse-checkout init --coneSet included directories
git sparse-checkout set [path1] [path2]Add another included path
git sparse-checkout add [path]Disable sparse checkout
git sparse-checkout disableSave changes to stash
git stash push -m "[message]"List stash entries
git stash listApply and drop the latest stash
git stash popApply a specific stash and keep it
git stash apply stash@{0}Drop a specific stash entry
git stash drop stash@{0}List tags
git tagCreate a lightweight tag
git tag [tag-name]Create an annotated tag
git tag -a [tag-name] -m "[tag message]"Push a specific tag
git push origin [tag-name]Push all tags
git push origin --tagsSet a custom hooks directory
git config core.hooksPath .githooksShow current hooks path
git config core.hooksPathUnset custom hooks path
git config --unset core.hooksPathMake a hook script executable
chmod +x .githooks/pre-commitAdd a submodule
git submodule add [url] [path]Init and fetch all submodules
git submodule update --init --recursiveUpdate submodules to remote latest
git submodule update --remote --recursiveShow submodule status
git submodule statusList worktrees
git worktree listCreate a worktree for a new branch
git worktree add ../[dir-name] -b [branch-name]Remove a worktree
git worktree remove ../[dir-name]Prune stale worktree records
git worktree pruneUndo the most recent commit and keep changes
git reset HEAD~1Soft reset the latest commit
git reset --soft HEAD~1Undo the N most recent commits and keep changes
git reset HEAD~NUndo the latest commit and discard changes
git reset HEAD~1 --hardRevert a commit with a new commit
git revert [commit-hash]Reset the current branch to remote state
git fetch origin
git reset --hard origin/[branch-name]Rename local master to main
git branch -m master mainCherry-pick a commit
git cherry-pick [commit-hash]Merge a branch into current branch
git merge [branch-name]Remove untracked files and directories
git clean -fdThis tool organizes common Git commands for configuration, status checks, staging, commits, branches, remotes, sync, history, bundles, archives, notes, filter-repo cleanup, bisect, repository checks, maintenance, rebase, replace refs, rerere conflict reuse, credential management, sparse checkout, tags, hooks, submodules, worktrees, stash, and rollback recovery so you can look them up and copy them quickly during development.
reset, amend, and --hard are highlighted as risky.No. It only shows and copies commands. It does not access your repository or execute terminal operations.
Because amend, reset, and --hard can rewrite history or discard changes, so they should be reviewed before use.