Git Cheatsheet

Interactive Git command reference organized by situation. Search, filter by category, and copy commands with one click.

All processing happens in your browser

39 commands

CautionUndo & Restore

Amend last commit

Modify the most recent commit message or add forgotten files to it.

SafeUndo & Restore

Undo last commit (keep staged)

Remove the last commit but keep all changes staged for re-commit.

CautionUndo & Restore

Undo last commit (keep unstaged)

Remove the last commit, unstage changes but keep them in working directory.

DestructiveUndo & Restore

Undo last commit (discard all)

Permanently remove the last commit and all its changes. Cannot be undone.

Irreversible

SafeUndo & Restore

Revert a commit

Create a new commit that undoes changes from a specific commit. Safe for shared branches.

SafeUndo & Restore

View reference log

Show history of all HEAD movements. Use this to recover lost commits or branches.

DestructiveUndo & Restore

Discard file changes

Discard uncommitted changes in a file, restoring it to the last committed state.

Irreversible

DestructiveUndo & Restore

Remove untracked files

Delete all untracked files and directories. Use git clean -n first to preview.

Irreversible

SafeBranches

List local branches

Show all local branches. Current branch is marked with an asterisk (*).

SafeBranches

Create & switch to new branch

Create a new branch from current HEAD and switch to it immediately.

CautionBranches

Delete a branch

Delete a local branch. Use -D instead of -d to force delete unmerged branches.

SafeBranches

Rename a branch

Rename a local branch. Use -M for current branch: git branch -M new-name.

SafeBranches

List all branches

Show all local and remote-tracking branches.

SafeBranches

Switch branch

Switch to an existing branch. Preferred over git checkout for clarity.

SafeStash

Stash changes

Temporarily save uncommitted changes and clean working directory.

SafeStash

Pop stash

Restore the most recent stash and remove it from the stash list.

SafeStash

List stashes

Show all saved stashes with their indices and descriptions.

CautionStash

Drop stash

Delete the most recent stash permanently. Specify index to drop a specific one.

SafeStash

Apply stash (keep in list)

Restore stashed changes without removing them from the stash list.

SafeRemote

List remotes

Show all configured remote repositories with their fetch and push URLs.

SafeRemote

Fetch all remotes

Download all branches and tags from all remote repositories without merging.

CautionRemote

Pull with rebase

Fetch and rebase local changes on top of remote. Avoids unnecessary merge commits.

SafeRemote

Push & set upstream

Push branch to remote and set it as the upstream tracking branch.

DestructiveRemote

Force push (safe)

Force push that fails if remote has new commits you haven't fetched. Safer than --force.

Irreversible

SafeHistory & Diff

Compact log

Show commit history with one line per commit: hash and message.

SafeHistory & Diff

Visual branch graph

Show commit history as an ASCII graph with all branches visualized.

SafeHistory & Diff

Show unstaged changes

Display line-by-line differences in modified files not yet staged.

SafeHistory & Diff

Show staged changes

Display changes that are staged and ready to be committed.

SafeHistory & Diff

Blame (line author)

Show who last modified each line of a file, with commit info.

CautionMerge & Rebase

Merge a branch

Integrate changes from another branch into current branch.

CautionMerge & Rebase

Rebase onto branch

Replay your commits on top of another branch for a linear history.

SafeMerge & Rebase

Abort merge

Cancel a merge in progress and restore pre-merge state. Use during conflicts.

CautionMerge & Rebase

Cherry-pick a commit

Apply changes from a specific commit to current branch without merging.

SafeStaging

Stage interactively

Choose specific hunks/lines to stage. Perfect for splitting changes into logical commits.

SafeStaging

Unstage a file

Remove a file from staging area without discarding changes.

CautionStaging

Untrack a file

Stop tracking a file in Git but keep it on disk. Useful after adding to .gitignore.

SafeConfig

Set user name

Configure your Git identity name for commits. Add --global for all repositories.

SafeConfig

Set user email

Configure your Git identity email for commits. Add --global for all repositories.

SafeConfig

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.

FAQ

Related Tools