Git Commands Cheat Sheet
A searchable Git commands cheat sheet covering init, clone, branch, merge, rebase, stash, and more. Copy any command instantly.
57 commands
git initInitialize a new local repository
git clone <url>Clone a remote repository locally
git config --global user.name "<name>"Set global username
git config --global user.email "<email>"Set global email
git statusShow working tree status
git logShow commit history
git log --onelineShow compact commit history
git log --graph --oneline --allShow branch graph
git diffShow unstaged changes
git diff --stagedShow staged changes
git show <commit>Show details of a commit
git blame <file>Show who changed each line
git add <file>Stage a specific file
git add .Stage all changes
git add -pInteractively stage hunks
git commit -m "<message>"Commit with a message
git commit --amendAmend the last commit
git reset HEAD <file>Unstage a file
git branchList all local branches
git branch -aList all branches (local + remote)
git branch <name>Create a new branch
git checkout <branch>Switch to a branch
git checkout -b <branch>Create and switch to a new branch
git switch <branch>Switch to a branch (modern syntax)
git switch -c <branch>Create and switch to a new branch (modern)
git branch -d <branch>Delete a merged branch
git branch -D <branch>Force delete a branch
git merge <branch>Merge a branch into current
git merge --no-ff <branch>Merge with a merge commit
git rebase <branch>Rebase current branch onto another
git rebase -i HEAD~<n>Interactive rebase last N commits
git cherry-pick <commit>Apply a specific commit to current branch
git remote -vList remote connections
git remote add origin <url>Add a remote named origin
git fetchDownload remote changes without merging
git pullFetch and merge remote changes
git pull --rebaseFetch and rebase remote changes
git push origin <branch>Push branch to remote
git push -u origin <branch>Push and set upstream tracking
git push --force-with-leaseSafe force push (checks remote state)
git stashStash current changes
git stash push -m "<message>"Stash with a description
git stash listList all stashes
git stash popApply and remove the latest stash
git stash apply stash@{n}Apply a specific stash
git stash drop stash@{n}Delete a specific stash
git revert <commit>Create a new commit that undoes a commit
git reset --soft HEAD~1Undo last commit, keep changes staged
git reset --mixed HEAD~1Undo last commit, keep changes unstaged
git reset --hard HEAD~1Undo last commit and discard changes
git restore <file>Discard unstaged changes in a file
git clean -fdRemove untracked files and directories
git tagList all tags
git tag <name>Create a lightweight tag
git tag -a <name> -m "<msg>"Create an annotated tag
git push origin --tagsPush all tags to remote
git tag -d <name>Delete a local tag
Related Developer Tools
What is Git Commands Cheat Sheet?
Git Commands Cheat Sheet is a free, searchable reference of the most commonly used Git commands. Browse commands by category — setup, branching, merging, remote, stash, and more — and copy any command with one click.
How to Use Git Commands
- Search for a command by name or description
- Filter by category using the buttons above
- Click the copy button to copy the command to your clipboard
- Paste it into your terminal and replace placeholders like <branch>
Features
- 57 commands across 9 categories
- Search by command name or description
- Filter by category: setup, branch, merge, remote, stash, undo, tags
- One-click copy for each command
FAQ
What do the angle brackets mean?
Angle brackets like <branch> are placeholders. Replace them with your actual value, e.g. git checkout main.
What is the difference between git fetch and git pull?
git fetch downloads remote changes but doesn't apply them. git pull fetches and then merges (or rebases) them into your current branch.
What is the safest way to undo a commit?
git revert is the safest — it creates a new commit that undoes the changes without rewriting history. Use git reset only on commits that haven't been pushed to a shared remote.