Yash Verma / Cloud runbook

Git commands

13 commands from the cloud runbook. Fill in a placeholder once and every command uses it.

Undo last commit (keep changes)

Undoes the last commit and keeps its changes in the working directory.

git reset HEAD~1

If the commit is already pushed, use git revert instead.

undo, reset

Force overwrite local branch

Discards local changes to match remote.

Caution. Destroys uncommitted changes and local commits that are not on the remote. Stash or branch first if in doubt.

git fetch --all && git reset --hard origin/<branch-name>

force, pull

Delete merged local branches

Deletes branches already merged into main.

git branch --merged main | grep -Ev '^\*|^[[:space:]]*(main|master)$' | xargs -r git branch -d

cleanup, branches

Stash specific files

Interactively choose which changes to stash.

git stash push -p -m "message"

stash, interactive

Interactive rebase (squash)

Starts an interactive rebase for the last N commits.

git rebase -i HEAD~3

rebase, squash, history

Cherry pick a commit

Applies the changes introduced by a specific commit from another branch.

git cherry-pick <commit-hash>

cherry-pick, commits

Fetch and prune remote branches

Fetches updates and removes local tracking branches that were deleted on remote.

git fetch -p

fetch, prune

Rebase onto origin main

Fetches and immediately rebases your current branch onto the latest origin/main.

git pull --rebase origin main

rebase, sync

Create annotated tag

Creates a version tag with a message.

git tag -a v1.0.0 -m 'Release v1.0.0'

tag, release

Binary search for bug (bisect)

Uses binary search to find the commit that introduced a bug.

git bisect start && git bisect bad && git bisect good <known-good-commit>

bisect, debug, history

Pretty git log graph

Shows a compact, colorful branch/merge history.

git log --oneline --graph --decorate --all

log, graph, history

Diff staged changes

Shows the diff of files staged for the next commit.

git diff --staged

diff, staged, review

Blame a file

Shows who last modified each line of a file.

git blame <filename>

blame, history, author