Tools

Git

Everyday version control — branches, commits, undo, and rebase.

Getting started

git initInitialize a repo
git clone <url>Clone a remote repo
git statusShow working tree status
git add <file>Stage a file
git add .Stage everything
git commit -m "msg"Commit staged changes
git commit -am "msg"Stage tracked + commit

Branches

git branchList branches
git branch <name>Create branch
git switch <name>Switch branch
git switch -c <name>Create + switch
git merge <name>Merge into current
git branch -d <name>Delete branch

Remote

git remote -vList remotes
git fetchDownload objects/refs
git pullFetch + merge
git pushUpload commits
git push -u origin <b>Push + set upstream

Undo & rewrite

git restore <file>Discard working changes
git restore --staged <f>Unstage
git commit --amendEdit last commit
git reset --soft HEAD~1Undo commit, keep changes
git reset --hard HEAD~1Undo commit + changes
git revert <hash>New commit that undoes one

--hard is destructive: it discards uncommitted work.

Stash

git stashShelve changes
git stash listList stashes
git stash popApply + drop latest
git stash applyApply, keep stash
git stash dropDelete a stash

Rebase & history

git log --onelineCompact history
git rebase <branch>Replay commits on top
git rebase -i HEAD~3Interactive rebase
git cherry-pick <hash>Apply one commit
git diffUnstaged changes
git blame <file>Who changed each line