Git & GitHub CLI Power Cheat Sheet
Customize variables live and copy ready-to-run Git & `gh` CLI commands for rebase, resets, stashing, and PR management.
Customize Command Variables
Undo last commit but keep changes staged
Undoes the last 3 commit(s) while retaining all your modifications in the staging area ready for re-committing.
git reset --soft HEAD~3Hard reset local branch to remote origin
Discards all uncommitted local changes and aligns your current branch state exactly with origin/feature/auth-v2.
git reset --hard origin/feature/auth-v2Modify last commit message or include newly staged files
Replaces the most recent commit with new staged changes and/or updated commit message.
git commit --amend -m "fix: resolve navigation state issue"Unstage a single file without losing modifications
Removes the specified file from the staging index while keeping your edits on disk.
git restore --staged components/navbar/NavbarClient.jsCreate and switch to new branch in one command
Creates a new branch and immediately checks it out for development.
git checkout -b feature/auth-v2Delete all local branches already merged into main
Safely deletes local branches whose changes have already been merged into main.
git branch --merged main | grep -v '^*' | xargs -n 1 git branch -dInteractive rebase to squash or edit past commits
Opens interactive terminal editor to reword, squash, or drop the last 3 commits.
git rebase -i HEAD~3Stash specific file with a descriptive message
Stashes modifications to a single specified file instead of stashing all modified files.
git stash push -m "WIP work on components/navbar/NavbarClient.js" -- components/navbar/NavbarClient.jsRemove untracked files and directories dry-run
Performs a dry-run showing which untracked files and folders will be permanently deleted.
git clean -fdnCompact one-line git log graph
Visualizes commit topology and branch merges in a clean one-line terminal format.
git log --graph --oneline --decorate --allView safety log to recover lost commits (Reflog)
Shows a chronological log of all HEAD movements, allowing recovery of deleted commits or aborted rebases.
git reflogCreate Pull Request via GitHub CLI
Creates a pull request directly from terminal and opens the browser PR page.
gh pr create --title "fix: resolve navigation state issue" --body "Automated PR from feature/auth-v2" --webCheckout PR by number to test locally
Downloads and switches to the remote branch of PR #42 for local testing.
gh pr checkout 42Cite & Link This Resource
Backlink MagnetWriting a blog post, GitHub README, or docs? Embed a backlink snippet or badge to cite this cheat sheet.
[Git & GitHub CLI Power Cheat Sheet](https://devdossier.com/resources/git-power-cheat-sheet) - Interactive Reference & Cheat Sheet via DevDossier