Cheatsheets
Git cheatsheet
Everyday clone, branch, commit, rebase, and undo commands.
Start and status
| Command / topic | What it does |
git clone <url> | Copy a remote repository |
git status | See staged, unstaged, and untracked files |
git log --oneline -n 10 | Short recent history |
git diff | Unstaged changes |
git diff --staged | Staged changes |
Branch and commit
| Command / topic | What it does |
git switch -c feature/x | Create and switch to a branch |
git add -p | Stage hunks interactively |
git commit -m "msg" | Commit staged changes |
git push -u origin HEAD | Publish the current branch |
git pull --rebase | Update with rebase instead of merge |
Undo safely
| Command / topic | What it does |
git restore <file> | Discard unstaged file changes |
git restore --staged <file> | Unstage without losing edits |
git reset --soft HEAD~1 | Undo last commit, keep changes staged |
git revert <sha> | Add a commit that undoes a past commit |
← All cheatsheets · Courses