Setup and Init

git initInitialize a new repo
git clone <url>Clone a repository
git config user.name "Name"Set name for commits
git config user.email "email"Set email for commits

Staging and Committing

git statusCheck working tree status
git add <file>Stage a specific file
git add .Stage all changes
git add -pStage changes interactively (patch mode)
git commit -m "msg"Commit with message
git commit --amendAmend last commit
git reset HEAD <file>Unstage a file
git diffShow unstaged changes
git diff --stagedShow staged changes

Branching

git branchList local branches
git branch <name>Create a branch
git checkout <branch>Switch to branch
git checkout -b <name>Create and switch to branch
git switch <branch>Switch to branch (modern)
git switch -c <name>Create and switch (modern)
git branch -d <name>Delete branch (safe)
git branch -D <name>Delete branch (force)
git branch -aList all branches (incl. remote)

Merging and Rebasing

git merge <branch>Merge branch into current
git rebase <branch>Rebase current onto branch
git rebase --abortAbort rebase
git rebase --continueContinue rebase after resolving
git merge --abortAbort merge
git cherry-pick <hash>Apply a single commit

Remote Operations

git remote -vList remotes
git remote add origin <url>Add a remote
git fetchFetch from remote
git pullPull (fetch + merge)
git pull --rebasePull (fetch + rebase)
git pushPush to remote
git push -u origin <branch>Push and set upstream
git push --force-with-leaseForce push (safer)

Stash

git stashStash working changes
git stash popApply and remove last stash
git stash applyApply last stash (keep it)
git stash listList all stashes
git stash dropDelete last stash
git stash -uStash including untracked files

Log and History

git logView commit history
git log --onelineCompact commit history
git log --graphVisual branch graph
git log -pLog with diffs
git show <hash>Show a specific commit
git blame <file>Show who changed each line
git reflogView reference log (recovery)

Undo and Reset

git checkout -- <file>Discard changes in file
git restore <file>Discard changes (modern)
git reset --soft HEAD~1Undo last commit, keep staged
git reset --mixed HEAD~1Undo last commit, keep unstaged
git reset --hard HEAD~1Undo last commit, discard all
git revert <hash>Create a commit that undoes a commit
git clean -fdRemove untracked files and dirs