Script Valley
Developer Environment Setup (WSL, Terminal, VS Code)
Git Workflows and Developer Best PracticesLesson 6.5

How to use Git stash, rebase, and cherry-pick for advanced workflows

git stash and pop, stash list, git rebase vs merge, interactive rebase squash, git cherry-pick, when to use each, rebase golden rule, force push caution

Git Stash, Rebase, and Cherry-Pick

Git advanced operations diagram

These three commands solve specific workflow problems that branches and merge alone cannot handle cleanly.

git stash — save work temporarily

git stash             # save uncommitted changes to a stack
git stash list        # see all stashed states
git stash pop         # restore the most recent stash
git stash drop        # discard the top stash

Use stash when you need to switch branches but are not ready to commit your current work.

git rebase — replay commits on a new base

git switch feature/login
git rebase main

Rebase keeps history linear. Never rebase commits that have been pushed to a shared branch — it rewrites history and breaks others clones.

Interactive rebase to squash commits

git rebase -i HEAD~3
# Change pick to squash on commits you want to merge

git cherry-pick — apply a specific commit

git cherry-pick a3f2c1b   # apply commit by hash to current branch

Useful for pulling a specific bug fix from one branch into another without merging the entire branch. Use git log --oneline to find the commit hash.