Git Commands Cheat Sheet
The everyday Git commands you actually use.
The Git commands that come up every day, grouped by task. Keep it handy until they're muscle memory.
Setup & config
| Command | What it does |
|---|---|
| git init | Start a new repository in the current folder |
| git clone <url> | Copy a remote repository locally |
| git config --global user.name "..." | Set your commit author name |
Everyday basics
| Command | What it does |
|---|---|
| git status | Show changed, staged and untracked files |
| git add <file> | Stage a file (use . for everything) |
| git commit -m "msg" | Commit the staged changes |
| git diff | Show unstaged changes |
| git log --oneline | Compact commit history |
Branching
| Command | What it does |
|---|---|
| git branch | List branches |
| git switch -c <name> | Create and switch to a new branch |
| git switch <name> | Switch to an existing branch |
| git merge <name> | Merge a branch into the current one |
Undo & fix
| Command | What it does |
|---|---|
| git restore <file> | Discard unstaged changes to a file |
| git restore --staged <file> | Unstage a file (keep the changes) |
| git commit --amend | Edit the last commit |
| git reset --hard <commit> | Reset everything to a commit (destructive) |
| git revert <commit> | Make a new commit that undoes another |
Remotes
| Command | What it does |
|---|---|
| git remote -v | Show configured remotes |
| git fetch | Download remote changes without merging |
| git pull | Fetch and merge remote changes |
| git push | Upload your commits to the remote |
FAQ
git fetch downloads remote changes but leaves your working branch alone; git pull fetches and then merges them into your branch.
Run git reset --soft HEAD~1 — it moves HEAD back one commit and leaves your changes staged.
Last reviewed 2026-08-20.