git

Git Command Cheatsheet

A searchable reference of the most useful git commands.

● runs in your browser
Setup & Config
git config --global user.name "Name"set your commit name
git config --global user.email "you@x.com"set your commit email
git initcreate a new repo in this folder
git clone <url>copy a remote repo locally
Daily Workflow
git statusshow changed/staged files
git add <file>stage a file (use . for all)
git commit -m "msg"commit staged changes
git commit -am "msg"stage tracked + commit in one step
git pullfetch + merge from remote
git pushsend commits to remote
Branches
git branchlist local branches
git switch -c <name>create & switch to a new branch
git switch <name>switch to an existing branch
git merge <name>merge a branch into current
git branch -d <name>delete a merged branch
Undo & Fix
git restore <file>discard unstaged changes to a file
git restore --staged <file>unstage a file
git commit --amendedit the last commit
git reset --hard HEADdiscard ALL local changes (careful)
git revert <hash>make a new commit undoing one
Inspect & History
git log --oneline --graphcompact visual history
git diffshow unstaged changes
git diff --stagedshow staged changes
git blame <file>who changed each line
git stash / git stash popshelve / restore work in progress
Remotes
git remote -vlist remotes
git remote add origin <url>add a remote
git push -u origin <branch>push & set upstream
git fetch --alldownload all remote changes