Everyday Workflow

git status -sb
Short status with branch info.
git diff
Show unstaged changes.
git diff --staged
Show staged changes.
git add <file>
Stage a specific file.
git add -A
Stage all changes, including deletes.
git add -p
Interactively stage chunks (great for clean commits).
git commit -m "message"
Create a commit with a message.
git commit -v
Review diff while writing the commit message.
git push
Push your branch to its upstream remote.
git log --oneline --graph --decorate --all
Compact, visual commit history with branches.

Branches and Remotes

git branch
List local branches; * marks current.
git branch -vv
Show branch tracking and last commit.
git branch -d <branch>
Delete a merged branch safely.
git branch -D <branch>
Force delete a branch (use with care).
git switch -c <branch>
Create and switch to a new branch.
git switch <branch>
Switch to an existing branch.
git merge <branch>
Merge another branch into the current branch.
git fetch --prune
Update remotes and remove deleted remote branches.
git pull --rebase
Fetch + rebase your work on top of remote (avoids merge bubbles).
git push -u origin <branch>
Create branch on remote and set upstream.
git remote -v
List remote names and URLs.
git remote add origin <url>
Add a new remote.

Undo and Fix-Ups

Warning: Commands that rewrite history (like reset --hard or push --force) are risky on shared branches. Prefer revert on main.

git restore <file>
Throw away unstaged changes in a file (reset to HEAD).
git restore --staged <file>
Unstage a file (keep changes in working tree).
git restore --source <commit> <file>
Restore a file from a specific commit.
git revert <commit>
Create a new commit that undoes a specific commit.
git reset --soft HEAD~1
Uncommit last commit but keep all changes staged.
git reset --mixed HEAD~1
Uncommit and unstage last commit, keep changes in working tree.
git reset --hard HEAD~1
Drop last commit and all related changes (destructive).
git reflog
Find lost commits and previous HEAD positions.

Stashing and Cleaning

git stash push -m "msg"
Stash current changes with a label.
git stash push -u -m "msg"
Stash tracked + untracked files.
git stash list
Show stashes with their indices.
git stash show -p stash@{0}
Preview what a stash contains.
git stash apply [stash@{n}]
Apply a stash, keep it in the list.
git stash pop
Apply the latest stash and drop it.
git stash drop stash@{n}
Remove a stash entry.
git clean -n
Preview which untracked files would be removed.
git clean -fd
Remove untracked files and directories.
git clean -fdx
Remove ignored files too (very destructive).

Rebasing and History Editing

git rebase main
Replay current branch on top of main.
git rebase -i HEAD~5
Interactively edit, squash, or drop the last 5 commits.
git commit --fixup <commit>
Create a fixup commit to autosquash later.
git rebase -i --autosquash HEAD~5
Automatically reorder fixup commits.
git rebase --continue
Continue rebase after resolving conflicts.
git rebase --abort
Abort the rebase and return to previous state.
git cherry-pick <commit>
Apply a single commit onto the current branch.
git push --force-with-lease
Force-push safely after rewriting history (checks remote head).

Inspection and Debugging

git log --stat
View commit history with file changes.
git show <commit>
Inspect a specific commit.
git diff <branch>..HEAD
Compare current branch to another.
git blame <file>
Find who last touched each line.
git bisect start
Begin binary search for a bad commit.
git bisect bad <commit>
Mark a known bad commit for the bisect.
git bisect good <commit>
Mark a known good commit for the bisect.
git bisect reset
End the bisect session and return to your branch.

Tags and Releases

git tag
List all tags.
git tag -a v1.2.0 -m "release"
Create an annotated tag.
git push origin --tags
Push tags to the remote.
git show v1.2.0
Inspect a tag and its commit.
git checkout v1.2.0
Checkout a tag in detached HEAD state.

Config and Helpers

git config --global user.name "Your Name"
Set the name used for commits.
git config --global user.email "name@example.com"
Set the email used for commits.
git config --global pull.rebase true
Use rebase instead of merge on pull.
git config --global init.defaultBranch main
Set the default branch name for new repos.
git config --global alias.lg "log --oneline --graph --decorate --all"
Create a handy log alias.

Worktrees

git worktree add ../repo-fix <branch>
Check out another branch in a new folder.
git worktree list
List active worktrees and their branches.
git worktree remove <path>
Remove a worktree when finished.