Git Cheat Sheet & Command Reference

Find any git command instantly with this searchable cheat sheet. Describe what you want to do in plain English and get the exact command, or browse by category to view all commands at once.

Ad Space

How Does This Git Command Lookup Work?

This tool is a free, searchable reference that helps developers find the exact git command they need without memorizing hundreds of options and flags. Instead of searching through documentation or Stack Overflow, you simply select a category that matches what you want to accomplish, and the tool displays a curated list of common git scenarios with the precise commands to run.

Each command entry includes a plain English description of what the command does, the exact syntax to copy and paste into your terminal, and a warning label for any destructive operations that cannot be easily undone. This makes it safe for beginners who might accidentally run a command that deletes their work, while still being useful for experienced developers who need a quick lookup for less frequently used git commands.

Why Use a Git Cheat Sheet?

Git is one of the most powerful version control systems available, but its command-line interface has a steep learning curve. Even experienced developers regularly forget the exact syntax for operations they perform infrequently, such as interactive rebasing, cherry-picking commits, or recovering deleted branches from the reflog. Having a categorized command reference eliminates the friction of searching through man pages or online forums.

The tool organizes commands into intuitive categories like Undo and Fix Mistakes, Branching and Merging, Stashing, Remote and Sync, History and Search, Cleanup and Maintenance, Configuration, and Advanced operations. This categorical approach helps developers discover related commands they may not have known about. For example, someone looking for how to undo a commit might also learn about git reflog for recovering lost work or git revert for safely undoing pushed commits.

Destructive vs Safe Commands

One of the most important features of this tool is the clear labeling of destructive commands. Operations like git reset --hard, git clean -fd, and git push --force can permanently delete uncommitted work or overwrite remote history. Each entry is marked with a visible warning so you can make an informed decision before running it. When a safer alternative exists, such as using git push --force-with-lease instead of git push --force, the safer option is recommended. All processing happens in your browser with no data sent to any server, making this a completely private and offline-capable reference.

Frequently Asked Questions

What is the safest way to undo a git commit?

If the commit has not been pushed, use git reset --soft HEAD~1 to undo the commit while keeping your changes staged. If the commit has already been pushed to a shared branch, use git revert HEAD to create a new commit that undoes the changes without rewriting history. Never use git reset --hard on shared branches as it rewrites history and can cause problems for other collaborators.

What is the difference between git merge and git rebase?

Git merge creates a new merge commit that combines two branches, preserving the complete history of both branches. Git rebase replays your commits on top of another branch, creating a linear history. Merge is safer for shared branches because it does not rewrite history, while rebase produces a cleaner commit log and is preferred for local feature branches before merging into main.

How do I recover a deleted git branch?

Use git reflog to find the SHA hash of the last commit on the deleted branch. The reflog keeps a record of all recent HEAD movements for about 90 days. Once you find the commit hash, run git checkout -b branch-name sha-hash to recreate the branch pointing to that commit. This works for locally deleted branches; for remote branches, check if another collaborator still has the branch.

What does git stash do and when should I use it?

Git stash temporarily saves your uncommitted changes (both staged and unstaged) and reverts your working directory to a clean state. Use it when you need to switch branches quickly without committing half-finished work, pull remote changes on a dirty working tree, or temporarily set aside experimental changes. Retrieve your stashed changes with git stash pop to apply and remove the stash, or git stash apply to apply while keeping the stash.

What is the difference between git fetch and git pull?

Git fetch downloads new commits and references from a remote repository but does not modify your working directory or current branch. Git pull is essentially git fetch followed by git merge — it downloads remote changes and immediately merges them into your current branch. Using git fetch is safer because it lets you review incoming changes before integrating them. You can also use git pull --rebase to rebase instead of merge when pulling.