A searchable git commands cheatsheet organized by workflow stage. Find the exact command for your situation — setup, staging, committing, branching, remote operations, and undoing changes.
How to Use the Git Commands Cheatsheet
This cheatsheet covers the core git commands used in daily development workflows. Filter by category to find commands for your current task, or use the search to find a specific command.
Basic Daily Workflow
The typical git workflow: git pull to get latest changes, make your edits, git add -p to stage changes interactively, git commit -m "message" to commit, and git push to share. Use git status and git diff frequently to verify your working state.
Feature Branch Workflow
Create a feature branch: git checkout -b feature/my-feature. Work and commit. When done: git rebase main to incorporate latest main changes cleanly, then open a pull request. Avoid merging main into your feature branch — rebasing keeps history linear.
Undoing Mistakes
Unstaged wrong file: git restore filename. Staged but not committed: git restore --staged filename. Committed locally: git reset --soft HEAD~1. Already pushed: git revert HEAD (safe for shared branches).
Frequently Asked Questions
Is this git cheatsheet free?
Yes, completely free with instant search. No account required.
What is the difference between git reset and git revert?
git reset moves the HEAD pointer backward, rewriting history — use only on local branches you haven't shared. git revert creates a new commit that undoes a previous commit, preserving history — safe to use on shared branches. On a shared branch, always prefer git revert over git reset --hard.
What is the difference between git fetch and git pull?
git fetch downloads remote changes without applying them — you can review them first with git diff origin/main. git pull is fetch + merge (or rebase, depending on config). Using git fetch before git merge gives you more control over when and how changes are integrated.
When should I use git rebase vs git merge?
git rebase rewrites commit history to create a linear history — great for keeping feature branch history clean before merging. git merge preserves the full history including when branches diverged. Rule of thumb: rebase local feature branches before merging to main; never rebase shared branches others have based work on.
What does git stash do?
git stash temporarily shelves uncommitted changes (both staged and unstaged) so you can switch branches or work on something else. Run git stash pop to reapply the most recent stash. You can have multiple stashes; use git stash list to see them and git stash apply stash@{N} to apply a specific one.
How do I undo the last commit but keep my changes?
Use git reset --soft HEAD~1 to undo the last commit while keeping all changes staged. Use git reset HEAD~1 (mixed mode) to undo the commit and unstage the changes (but keep files). Use git reset --hard HEAD~1 to discard the commit AND all changes permanently — use with caution.