Utility Empire

Git - Quick Reference

Config, everyday workflow, branching, undo, remotes and recovery tactics for single-developer and team use. All rows are plain text - search to filter, click Copy to grab the pattern.

Reference rack
STATUSREADY
ROWS44
NETWORKLOCAL
MODEREFERENCE
Item / patternWhat it means / how to use it
git initCreate an empty repository in the current folder.
git clone <url>Copy a remote repository to your machine with full history.
git config --global user.name "X"+ user.email - the identity stamped on your commits.
git config --global core.editor "code --wait"Default commit/tag message editor.
git config --global init.defaultBranch mainSet main as the default branch name for new repositories.
git statusState of the working tree: staged, unstaged, untracked.
git add <file> / git add .Stage one file / everything changed.
git commit -m "message"Snapshot the staged changes.
git commit -am "message"Stage tracked modifications and commit in one step.
git log --oneline --graphConcise history with the branch graph.
git diff / git diff --stagedWorking tree vs index / index vs last commit.
git show <commit>Full diff and metadata of a single commit.
git rm <file>Remove a file and stage the deletion.
git mv <old> <new>Rename a file and stage it.
git branch <name>Create a branch.
git branch -aList local and remote branches.
git checkout <branch> / git switch <branch>Move to another branch.
git checkout -b <name> / git switch -c <name>Create a branch and switch to it in one step.
git merge <branch>Fold the named branch into the current branch.
git rebase <branch>Re-apply your commits on top of another branch for a linear history.
git branch -d <name>Delete a merged branch; -D force-deletes an unmerged one.
git push origin <branch>Upload the branch and set the upstream at once.
git restore <file>Discard working-tree changes to that file.
git restore --staged <file>Unstage a file while keeping your edits.
git reset --soft HEAD~1Undo the last commit but keep the changes staged.
git reset --hard <sha>Discard everything back to a commit - destructive, think twice.
git revert <sha>A new commit that reverses an old one; safe on shared history.
git stash / git stash popPark work in progress aside, then bring it back.
git clean -fdDelete untracked files and directories - destructive.
git remote -vList remotes and their fetch/push URLs.
git remote add origin <url>Attach a remote named origin.
git fetch <remote>Download remote refs without touching your working tree.
git pull / git pull --rebaseFetch then merge / fetch then replay your commits on top.
git push -u origin <branch>Push and record the upstream tracking for future pulls.
git tag <name> / git tag -a -m "msg"Create lightweight / annotated (release-worthy) tags.
git log --oneline --author=X --since=2.weeksHistory filtered by author and time.
git blame <file>Who changed which line last - per-line attribution.
git grep <pattern>Search the contents of tracked files, not just filenames.
git diff HEAD~1 HEADThe delta between two commits.
git reflogThe local log of every HEAD move - the way to resurrect "lost" commits.
git bisect startThen mark bad/good commits to binary-search the change that broke behavior.
git worktree add <path> <branch>Check out a branch in a separate folder for parallel work.
git archive --format=zip -o src.zip HEADExport a clean zip of one commit; no .git history.
.gitignorePatterns of files to keep untracked - node_modules/, .env, build outputs.