← Lesson
BitWithBite
Git & GitHub · Quick Reference

Lesson 7 — Advanced Git Cheat Sheet

Git & GitHub
In one line: You're deep in a feature when a critical bug report comes in — you need to switch branches immediately, but your work isn't ready to commit. git stash is your escape hatch: it s...

Key Ideas

1Git Stash — Save Work in Progress. You're deep in a feature when a critical bug report comes in — you need to switch branches immediately, but your work isn't ready to commit. git stash is your escape h...
2Interactive Rebase — Rewrite History. Interactive rebase lets you rewrite your commit history before pushing. This is how professionals keep their PRs clean: squash messy "WIP" commits into meaningful ones...
3Cherry-Pick — Apply Specific Commits. git cherry-pick copies a specific commit from anywhere in history and applies it to your current branch. It's like saying "I want exactly this change, and nothing else...
4Resetting Commits — Three Modes. git reset moves HEAD (and the branch pointer) backwards in history. The three modes control what happens to your working directory and staging area after the reset. Ch...
5Git Reflog — Your Safety Net. The reflog (reference log) records every movement of HEAD in your repository — even after resets, rebases, branch deletions, and other "destructive" operations. It's G...

Code Examples

# Stash current uncommitted changes (tracked files) git stash # Stash with a descriptive message (highly recommended) git stash save "WIP: feature X — halfway through the auth logic" # Also stash untracked (new) files git stash -u # List all stashes git ...
# Rebase the last 3 commits interactively git rebase -i HEAD~3 # This opens your configured editor with something like: # # pick a1b2c3d feat: add user model # pick d4e5f6g WIP: testing stuff # pick h7i8j9k fix: forgot to save # # Change 'pick' to: # squa...
# Apply a single commit to current branch git cherry-pick a3f5b2c # Apply multiple commits git cherry-pick a3f5b2c d7e9f1a # Apply a range of commits (from..to, exclusive of first) git cherry-pick a3f5b2c..d7e9f1a # Cherry-pick without committing (stage ...