Stash, Tags & Cherry-pick
Stash, Tags & Cherry-pick
Section titled “Stash, Tags & Cherry-pick”📦 git stash — Save Work In Progress
Section titled “📦 git stash — Save Work In Progress”stash temporarily saves your uncommitted changes so you can switch branches.
Think of it like putting your work in a drawer so you can do something else, then take it back out.
# Save current work (untracked + staged)git stash
# Save including untracked filesgit stash -u
# List all stashesgit stash list# stash@{0}: WIP on main: fix login bug# stash@{1}: WIP on feature: add dark mode
# Apply the most recent stash (keeps it in list)git stash apply
# Apply and remove from listgit stash pop
# Apply a specific stashgit stash apply stash@{1}
# Drop (delete) a stashgit stash drop stash@{0}
# Clear all stashesgit stash clearTypical workflow:
# 1. You're working on featuregit checkout -b feature-dark-mode# (edit files)
# 2. Urgent bug on main! Save your workgit stash -u
# 3. Switch and fix buggit checkout main# (fix the bug, commit, push)git checkout feature-dark-mode
# 4. Get your work backgit stash popResult: Your half-finished work is saved, you fix the urgent bug, then get back to work.
🏷️ git tag — Mark Important Commits
Section titled “🏷️ git tag — Mark Important Commits”Tags mark specific commits, usually for releases (v1.0, v2.0).
# Create a lightweight taggit tag v1.0
# Create an annotated tag (with message — recommended)git tag -a v1.0 -m "Release version 1.0"
# List all tagsgit tag# v1.0# v1.1# v2.0
# Tag a specific commitgit tag -a v1.0 a1b2c3d -m "Release v1.0"
# Push tags to GitHubgit push origin --tags
# Delete a local taggit tag -d v1.0
# Delete a remote taggit push origin --delete v1.0
# Checkout a tag (detached HEAD)git checkout v1.0🍒 git cherry-pick — Apply Specific Commits
Section titled “🍒 git cherry-pick — Apply Specific Commits”cherry-pick applies a specific commit from one branch to your current branch.
Think of it like picking one cherry from another tree and putting it on yours.
flowchart LR subgraph BranchA[Feature Branch] A1[A → B → C → D] end
subgraph BranchB[Main Branch] B1[A → B → E → F] end
A1 -- cherry-pick commit C --> B1 B1 --> Result[A → B → E → F → C']
style BranchA fill:#3b82f6,color:#fff style BranchB fill:#10b981,color:#fff style Result fill:#7c3aed,color:#fff# Cherry-pick a single commitgit cherry-pick a1b2c3d
# Cherry-pick a range of commitsgit cherry-pick a1b2c3d..f6e5d4c
# Cherry-pick without committing (make changes to working directory)git cherry-pick -n a1b2c3dUse cherry-pick when:
- A bug fix was committed on a different branch and you need it here
- You want to bring a specific feature without merging an entire branch
- You accidentally committed to the wrong branch
In Simple Words
Section titled “In Simple Words”git stashsaves work temporarily — like putting files in a drawergit tagmarks important commits with names likev1.0for releasesgit cherry-pick <commit>applies a specific commit to your current branch- Stash is for half-finished work, tags are for releases, cherry-pick is for selective commits
- Push tags with
git push --tagsso they appear on GitHub