Skip to main content

Git Commands Cheat Sheet

Tools

Git Commands Cheat Sheet

# Git Commands Cheat Sheet

The commands you reach for every day.

Setup & basics

CommandWhat it does
git initStart a new repository
git clone <url>Copy a remote repository
git statusShow working-tree state
git add <file>Stage changes
git commit -m "msg"Record staged changes

Branching & merging

CommandWhat it does
git branchList branches
git switch -c <name>Create and switch to a branch
git merge <branch>Merge a branch into current
git rebase <branch>Reapply commits on top of another base

Remotes

CommandWhat it does
git remote -vList remotes
git fetchDownload remote changes
git pullFetch + merge
git pushUpload commits

Undoing things

CommandWhat it does
git restore <file>Discard working changes
git reset --soft HEAD~1Undo last commit, keep changes staged
git revert <commit>Create a commit that undoes another
← All cheat sheets