Git Essential Workflows & Undo Commands Cheatsheet
Quick reference for daily Git operations: branching, interactive rebasing, stash management, cherry-picking, and undoing commits.
Advertisement
Developer Cloud IDE & Database Sponsor
1. Branching & Synchronization
Rebasing during pull prevents unnecessary merge commits and maintains clean git history.
CODE SNIPPET
# Create and switch to a new feature branch
git checkout -b feature/auth-flow
# Pull with rebase to keep clean linear history
git pull --rebase origin main
# Push branch and set upstream tracking
git push -u origin feature/auth-flow
2. Emergency Undos & Recovery
git reflog records every head movement, allowing you to recover commits even after accidental deletions.
CODE SNIPPET
# Undo last commit but keep modified files in staging area
git reset --soft HEAD~1
# Discard all unstaged changes in working tree
git restore .
# Find lost commits or branches after bad rebase
git reflog
git reset --hard HEAD@{2}
Need another cheat sheet?
We add new reference guides every week based on community requests.
Request a Cheatsheet →