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

CommandWhat it does
git initStart 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

CommandWhat it does
git statusShow changed, staged and untracked files
git add <file>Stage a file (use . for everything)
git commit -m "msg"Commit the staged changes
git diffShow unstaged changes
git log --onelineCompact commit history

Branching

CommandWhat it does
git branchList 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

CommandWhat it does
git restore <file>Discard unstaged changes to a file
git restore --staged <file>Unstage a file (keep the changes)
git commit --amendEdit the last commit
git reset --hard <commit>Reset everything to a commit (destructive)
git revert <commit>Make a new commit that undoes another

Remotes

CommandWhat it does
git remote -vShow configured remotes
git fetchDownload remote changes without merging
git pullFetch and merge remote changes
git pushUpload 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.