Cheatsheets & Reference
Git Command Cheatsheet
Categorized Git commands with copy buttons and undo pairings.
Setup & Config
5git init Initialize a new Git repository in the current directory.
git clone <url> Clone a remote repository to your local machine.
git config --global user.name "Name" Set your global commit author name.
git config --global user.email "email" Set your global commit email address.
git config --list List all Git configuration settings.
Staging & Committing
7git status Show the working tree status (modified, staged, untracked files).
git add <file> Stage a specific file for the next commit.
git add . Stage all changes in the current directory.
git commit -m "message" Commit staged changes with a message.
git commit --amend Modify the most recent commit (message or content).
Undo: git reflog → git reset --hard <hash>
git diff Show unstaged changes in the working directory.
git diff --staged Show changes that are staged for the next commit.
Branching
10git branch List all local branches. Current branch is marked with *.
git branch <name> Create a new branch (does not switch to it).
git checkout <branch> Switch to an existing branch.
git checkout -b <branch> Create a new branch and switch to it.
git switch <branch> Switch branches (modern alternative to checkout).
git switch -c <branch> Create and switch to a new branch.
git branch -d <branch> Delete a branch (safe — only if fully merged).
Undo: git branch <name> <hash> (use reflog to find hash)
git branch -D <branch> Force-delete a branch even if not merged.
git merge <branch> Merge a branch into the current branch.
Undo: git merge --abort (during conflict) or git reset --hard HEAD~1 (after merge)
git rebase <branch> Rebase current branch onto another branch.
Undo: git rebase --abort (during rebase) or git reflog → git reset --hard <hash>
Undoing Changes
7git restore <file> Discard working directory changes for a file.
git restore --staged <file> Unstage a file (keep working directory changes).
git reset HEAD~1 Undo the last commit, keep changes staged.
Undo: git reflog → git reset --hard <hash>
git reset --soft HEAD~1 Undo the last commit, keep changes in staging area.
git reset --hard HEAD~1 Undo the last commit AND discard all changes.
Undo: git reflog → git reset --hard <hash>
git revert <commit> Create a new commit that undoes a specific commit.
git clean -fd Remove untracked files and directories.
Remote Repositories
9git remote -v List all remote repositories with their URLs.
git remote add origin <url> Add a remote repository named "origin".
git push origin <branch> Push a branch to the remote repository.
git push -u origin <branch> Push and set upstream tracking for the branch.
git push --force Force-push (overwrites remote history — use with caution).
git pull Fetch from remote and merge into the current branch.
git pull --rebase Fetch from remote and rebase local commits on top.
git fetch Download objects and refs from remote without merging.
git fetch --prune Fetch and remove any remote-tracking refs that no longer exist.
Stashing
7git stash Stash uncommitted changes (staged and unstaged).
git stash push -m "message" Stash changes with a descriptive message.
git stash list List all stashed changesets.
git stash pop Apply the most recent stash and remove it from the list.
git stash apply Apply the most recent stash without removing it.
git stash drop Delete the most recent stash entry.
git stash clear Delete all stashed entries.
History & Inspection
7git log Show the commit history for the current branch.
git log --oneline Show commit history in compact one-line format.
git log --graph --oneline --all Show a visual graph of all branches.
git show <commit> Show details and diff of a specific commit.
git blame <file> Show who last modified each line of a file.
git reflog Show a log of all reference updates (useful for recovery).
git shortlog -sn Show commit count per author, sorted.
Tags
5git tag List all tags.
git tag v1.0.0 Create a lightweight tag at the current commit.
git tag -a v1.0.0 -m "msg" Create an annotated tag with a message.
git push origin --tags Push all tags to the remote repository.
git tag -d v1.0.0 Delete a local tag.
The Complete Git Commands Cheatsheet
Git is the most widely used version control system in software development, powering platforms like GitHub, GitLab, and Bitbucket. Whether you're a beginner learning version control for the first time or a seasoned developer who needs a quick reference, this Git commands cheatsheet covers every essential operation you'll need in your daily workflow. Every command is categorized — from basic setup and staging to advanced branching, rebasing, and recovery techniques using git reflog. Each entry includes a plain-English explanation so you understand not just what a command does, but when to use it. Use the search bar above to instantly find the command you need, and the copy button to grab it with one click.
Frequently Asked Questions
How do I undo the last Git commit?
Use git reset --soft HEAD~1 to undo the commit but keep your changes staged.
Use git reset HEAD~1 to undo the commit and unstage the changes (they stay in your working directory).
Use git reset --hard HEAD~1 to undo the commit and discard all changes entirely.
If you've already pushed the commit, use git revert HEAD instead, which creates a new commit that undoes the previous one without rewriting history.
What's the difference between git merge and git rebase?
Merge creates a new "merge commit" that combines two branches, preserving the full history of both. Rebase replays your branch's commits on top of the target branch, creating a linear history. Use merge for shared/public branches (like main) and rebase for cleaning up local feature branches before merging.
How do I recover a deleted branch in Git?
Run git reflog to find the commit hash where the branch was pointing before deletion.
Then recreate the branch with git branch <branch-name> <hash>.
The reflog keeps references for at least 30 days by default, so you have a good window for recovery.
What does git stash do?
git stash temporarily saves your uncommitted changes (both staged and unstaged) so you can switch branches or pull updates without committing incomplete work.
Use git stash pop to reapply the changes later. You can maintain multiple stashes and label them with git stash push -m "description".
Is my data sent to any server?
No. This cheatsheet is entirely static HTML rendered in your browser. No data is collected, transmitted, or stored. The search and copy functionality runs 100% client-side.