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.
13 commands from the cloud runbook. Fill in a placeholder once and every command uses it.
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.
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>
Deletes branches already merged into main.
git branch --merged main | grep -Ev '^\*|^[[:space:]]*(main|master)$' | xargs -r git branch -d
Interactively choose which changes to stash.
git stash push -p -m "message"
Starts an interactive rebase for the last N commits.
git rebase -i HEAD~3
Applies the changes introduced by a specific commit from another branch.
git cherry-pick <commit-hash>
Fetches updates and removes local tracking branches that were deleted on remote.
git fetch -p
Fetches and immediately rebases your current branch onto the latest origin/main.
git pull --rebase origin main
Creates a version tag with a message.
git tag -a v1.0.0 -m 'Release v1.0.0'
Uses binary search to find the commit that introduced a bug.
git bisect start && git bisect bad && git bisect good <known-good-commit>
Shows a compact, colorful branch/merge history.
git log --oneline --graph --decorate --all
Shows the diff of files staged for the next commit.
git diff --staged
Shows who last modified each line of a file.
git blame <filename>