Essential Git Commands Cheat Sheet
Ad
Git Commands Cheat Sheet
The most-used Git commands, organized by task. Bookmark this for quick reference.
Setup
git config --global user.name "Your Name"
git config --global user.email "you@email.com"
git init # new repo
git clone <url> # copy a repo
Daily Workflow
git status # what changed
git add . # stage all
git commit -m "msg" # commit
git push # upload
git pull # download + merge
Branching
git branch # list
git checkout -b new # create + switch
git switch main # switch
git merge feature # merge
git branch -d feature # delete
Undoing Things
git restore file.js # discard changes
git reset --soft HEAD~1 # undo last commit, keep changes
git reset --hard HEAD~1 # undo + discard (careful!)
git revert <hash> # safe undo (new commit)
Inspecting
git log --oneline # compact history
git diff # unstaged changes
git show <hash> # show a commit
FAQs
reset vs revert?
reset rewrites history; revert safely undoes via a new commit. More in our Git section.
How do I undo git add?
git restore --staged file.js.
