Git Cheatsheet
Interactive Git command reference organized by situation. Search, filter by category, and copy commands with one click.
39 commands
Amend last commit
Modify the most recent commit message or add forgotten files to it.
Undo last commit (keep staged)
Remove the last commit but keep all changes staged for re-commit.
Undo last commit (keep unstaged)
Remove the last commit, unstage changes but keep them in working directory.
Undo last commit (discard all)
Permanently remove the last commit and all its changes. Cannot be undone.
Irreversible
Revert a commit
Create a new commit that undoes changes from a specific commit. Safe for shared branches.
View reference log
Show history of all HEAD movements. Use this to recover lost commits or branches.
Discard file changes
Discard uncommitted changes in a file, restoring it to the last committed state.
Irreversible
Remove untracked files
Delete all untracked files and directories. Use git clean -n first to preview.
Irreversible
List local branches
Show all local branches. Current branch is marked with an asterisk (*).
Create & switch to new branch
Create a new branch from current HEAD and switch to it immediately.
Delete a branch
Delete a local branch. Use -D instead of -d to force delete unmerged branches.
Rename a branch
Rename a local branch. Use -M for current branch: git branch -M new-name.
List all branches
Show all local and remote-tracking branches.
Switch branch
Switch to an existing branch. Preferred over git checkout for clarity.
Stash changes
Temporarily save uncommitted changes and clean working directory.
Pop stash
Restore the most recent stash and remove it from the stash list.
List stashes
Show all saved stashes with their indices and descriptions.
Drop stash
Delete the most recent stash permanently. Specify index to drop a specific one.
Apply stash (keep in list)
Restore stashed changes without removing them from the stash list.
List remotes
Show all configured remote repositories with their fetch and push URLs.
Fetch all remotes
Download all branches and tags from all remote repositories without merging.
Pull with rebase
Fetch and rebase local changes on top of remote. Avoids unnecessary merge commits.
Push & set upstream
Push branch to remote and set it as the upstream tracking branch.
Force push (safe)
Force push that fails if remote has new commits you haven't fetched. Safer than --force.
Irreversible
Compact log
Show commit history with one line per commit: hash and message.
Visual branch graph
Show commit history as an ASCII graph with all branches visualized.
Show unstaged changes
Display line-by-line differences in modified files not yet staged.
Show staged changes
Display changes that are staged and ready to be committed.
Blame (line author)
Show who last modified each line of a file, with commit info.
Merge a branch
Integrate changes from another branch into current branch.
Rebase onto branch
Replay your commits on top of another branch for a linear history.
Abort merge
Cancel a merge in progress and restore pre-merge state. Use during conflicts.
Cherry-pick a commit
Apply changes from a specific commit to current branch without merging.
Stage interactively
Choose specific hunks/lines to stage. Perfect for splitting changes into logical commits.
Unstage a file
Remove a file from staging area without discarding changes.
Untrack a file
Stop tracking a file in Git but keep it on disk. Useful after adding to .gitignore.
Set user name
Configure your Git identity name for commits. Add --global for all repositories.
Set user email
Configure your Git identity email for commits. Add --global for all repositories.
Show all config
Display all Git configuration settings from all levels (system, global, local).
About Git Commands
Git is a distributed version control system used by the vast majority of software developers worldwide. Created by Linus Torvalds in 2005, Git tracks changes in source code and enables collaborative development across teams of any size.
Browse commands organized by category (Undo, Branch, Stash, Remote, History, Merge, Staging, Config) or use the search bar to find commands by keyword. Each command shows the exact syntax, a clear description, and a safety level badge. Click any command to copy it to your clipboard instantly.
This cheatsheet covers the most common Git scenarios developers encounter daily: undoing mistakes, managing feature branches, stashing work in progress, collaborating with remote repositories, reviewing commit history, resolving merge conflicts, and configuring Git settings.
Commands are color-coded by safety level — green for safe operations that do not modify history, yellow for commands that require caution, and red for destructive operations that can cause permanent data loss. Always preview destructive commands with dry-run flags before executing them on important repositories.