CHEATSHEET • GIT & GITHUB CLI
Git & GitHub CLI (gh) Cheatsheet
Daily version control commands for clean branching, rebasing, stash workflows, emergency reflog recovery, release tagging, and GitHub Actions CLI control.
01Branching, Rebasing & History Inspection
Create and switch to a new feature branch from current HEAD
git switch -c feat/eks-autoscaling
Fetch upstream changes and rebase your feature branch cleanly onto main
git fetch origin && git rebase origin/main
Display compact commit graph across all branches and tags
git log --oneline --graph --decorate --all -n 20
Review staged changes ready for your next commit
git diff --staged
Update the last unpushed commit message or add forgotten files
git commit --amend --no-edit
02Undo, Stash & Emergency Recovery
Unstage a file while keeping your local edits intact
git restore --staged <file>
Undo the last commit locally while keeping changes staged
git reset --soft HEAD~1
Safely revert a pushed commit by creating a new inverse commit
git revert <commit-sha>
Stash tracked and untracked changes temporarily, then restore
git stash push -u -m "wip" && git stash pop
Inspect local HEAD history to recover commits after a hard reset
git reflog -n 15
Advertisement
03Release Tagging & GitHub CLI (gh)
Create an annotated release tag and push it to trigger CI/CD
git tag -a v1.4.0 -m "Release v1.4.0" && git push origin v1.4.0
Create a Pull Request or check out a teammate's PR locally
gh pr create --fill && gh pr list
Trigger a GitHub Actions workflow and watch live run status
gh workflow run ci.yml && gh run watch
Set an encrypted repository secret for GitHub Actions
gh secret set DEPLOY_TOKEN --body "<token>"