Git cheatsheet
A compact Git command cheatsheet covering setup, staging, commits, branches, remotes, undo, and history. Copy commands as needed.
Initialize repository
git initClone repository
git clone <url>Set user name
git config --global user.name "<name>"Set user email
git config --global user.email "<email>"Status
git statusStage file
git add <file>Stage all
git add .Commit
git commit -m "<message>"Amend commit
git commit --amendList branches
git branchCreate branch
git branch <name>Switch branch
git switch <name>Create and switch
git switch -c <name>Merge branch
git merge <branch>List remotes
git remote -vAdd remote
git remote add origin <url>Push
git push -u origin <branch>Pull
git pullFetch
git fetch --allLog
git log --oneline --graphUnstage file
git restore --staged <file>Discard changes
git restore <file>Soft reset
git reset --soft HEAD~1Stash
git stash push -m "<message>"// About this tool
Keep common Git commands within reach while working in a terminal. Browse commands grouped by task and copy the exact syntax you need. Commands are grouped by everyday tasks.
// How to use it
- Find the task you need, such as branches or remotes.
- Review the command syntax.
- Copy the command into your terminal.
// Frequently asked questions
Does it run Git commands?
No. It is a reference; commands are copied and run in your own terminal.
Are the commands safe to run?
Read them first, especially destructive commands such as reset or clean.