Git Cheat Sheet
Git commands, workflow, branching strategies, and best practices.
1 PageBeginnerMay 14, 2026
Basic Commands
Essential everyday Git commands.
bash
git init # Init repogit clone <url> # Clone remotegit status # Working tree statusgit add . # Stage all changesgit commit -m "message" # Create commitgit push origin main # Push to remote
Branching
Create and manage branches.
bash
git branch feature/login # Create branchgit checkout feature/login # Switch branchgit checkout -b feature/x # Create & switchgit merge feature/login # Merge branchgit branch -d feature/login # Delete branch
Remotes: Push, Pull, Fetch
Sync work with remote repositories.
bash
git remote -v # list remotesgit remote add origin <url>git fetch origin # download, don't mergegit pull origin main # fetch + mergegit push -u origin main # push and set upstreamgit push origin --delete old-branch # delete remote branch
Undoing Changes
Revert, reset, and restore work safely.
bash
git restore file.txt # discard unstaged changesgit restore --staged file.txt # unstage, keep changesgit commit --amend # edit last commitgit revert <sha> # new commit that undoes <sha>git reset --soft HEAD~1 # undo commit, keep stagedgit reset --hard HEAD~1 # discard commit AND changes
Stash & Inspecting History
Shelve work and explore the log.
bash
git stash # shelve uncommitted workgit stash pop # restore latest stashgit stash listgit log --oneline --graph --allgit log -p file.txt # history with diffsgit diff HEAD~2 HEAD # compare commitsgit blame file.txt # who changed each line
Interactive Rebase & Cherry-Pick
Rewrite local history and move individual commits.
bash
git rebase -i HEAD~3 # squash/reorder/edit last 3 commitsgit rebase main # replay current branch on top of maingit rebase --continue # after resolving a conflictgit rebase --abort # bail out, restore original stategit cherry-pick <sha> # apply one commit onto current branchgit cherry-pick <sha> --no-commit # stage it without committing
Pro Tip
Write descriptive commit messages in the imperative mood: "Add feature" not "Added feature".
Was this cheat sheet helpful?