How to use the Git Commands Cheat Sheet
- 1. Search a taskType undo, stash or branch to find the right command.
- 2. Read the warningCards say when a command rewrites history or deletes work.
- 3. DownloadKeep your filtered list as a text file.
The everyday loop
Most work is a short loop: git status to see what changed, git add -p to stage the parts you mean, git commit -m "Add login form" to save them, and git push. Start new work on a branch with git switch -c feature/login, which is the modern replacement for checkout -b. Before you open a pull request, git pull --rebase keeps your commits on top of the latest main.
Write commit messages in the imperative, as if completing the sentence If applied, this commit will…: Add, Fix, Update, Remove.
Undoing things, from safest to riskiest
git restore filethrows away unstaged edits to one file.git restore --staged fileunstages but keeps the edit.git commit --amendfixes the last commit before you push.git revert <commit>adds a new commit that undoes an old one, safe on shared branches.git reset --hard HEAD~1moves the branch back and deletes changes. Use with care.
If something disappears, git reflog lists every place HEAD has been, so you can usually get committed work back. git clean -fd deletes untracked files for good; preview first with -n. See how branches and merges look as a picture in the Git branching visualizer, and set up ignore rules with the .gitignore generator.
Frequently asked questions
Should I use git switch or git checkout?
Both work. switch and restore were added in Git 2.23 to split checkout's two jobs, so they are clearer for beginners.
When should I rebase instead of merge?
Rebase your own local or private branch to keep history straight. Merge shared branches, because rebasing rewrites commits others may have.
Is the Git Commands Cheat Sheet free?
Yes, the Git Commands Cheat Sheet is free. The first time you download your first cheat sheet, you are asked for your name and WhatsApp number once. After that, this and every other Uncodemy tool opens straight away without the form.