HomeBytesheetsRoadmapsUI TemplatesUI ToolsStack Discussion
4 Topics
Chapter•40 Minutes

Stash, Cherry-Pick, Tags, and Releases

Learn practical tools for temporarily shelving work, selectively transferring commits, marking releases, and managing versions.

Temporarily Stashing Work

git stash temporarily saves working-tree and staging changes so you can switch context without committing incomplete work. A stash is stored in Git's stash references and can later be applied or popped.

Modern Git also supports git stash push -m for descriptive stash messages and git stash push -u to include untracked files.

Stash and Restore Work
git stash push -m "WIP login validation"
git switch main
git switch feature/login
git stash list
git stash pop
💡 stash push saves the changes. stash list shows saved entries, while stash pop applies the latest stash and removes it if successful.
Key Takeaways
  • Stash is useful for temporarily incomplete work.
  • Use descriptive stash messages when maintaining multiple entries.
  • Stashes can conflict when applied to changed code.
Knowledge Check

What is the primary purpose of `git stash`?

Cherry-Picking Commits

git cherry-pick applies the changes introduced by selected commits onto the current branch. It is useful when one specific fix is needed without merging an entire branch.

Cherry-picking creates a new commit on the destination branch, so the resulting commit normally has a different hash from the original.

Apply a Specific Fix
git switch release/1.4
git cherry-pick abc1234
💡 Git applies the changes from commit abc1234 to the current branch and creates a new commit containing those changes.
Key Takeaways
  • Cherry-pick is useful for selective commit transfer.
  • The resulting commit is normally a new commit with a different hash.
  • Cherry-picking can introduce conflicts.
Knowledge Check

What does cherry-pick primarily do?

Tags and Versioning

Tags are references used to mark important points in history, commonly releases such as v1.0.0. Lightweight tags point directly to an object, while annotated tags store additional metadata such as tagger information, message, and date.

Create a Release Tag
git tag -a v1.0.0 -m "Release 1.0.0"
git tag
git show v1.0.0
git push origin v1.0.0
💡 The annotated tag marks the current commit with release metadata. Tags must be explicitly pushed unless using an appropriate tag push command.
Key Takeaways
  • Tags are useful for marking releases.
  • Annotated tags contain metadata and are generally preferred for releases.
  • Tags are not automatically pushed with ordinary branch pushes.
Knowledge Check

Which command creates an annotated tag?

Advanced History Inspection

Git history can be queried in many ways. git log --author, --grep, --since, path filters, and graph formatting allow you to locate specific changes. git blame identifies the commit associated with each line of a file and can be useful when investigating historical decisions.

Use Blame for Context, Not Blame

git blame is most useful for finding the commit and author associated with a line so you can inspect the surrounding historical context.

Search Git History
git log --oneline --all --grep="authentication"
git log --author="Suriya" --oneline
git log -- src/auth.js
git blame src/auth.js
💡 These commands search commit messages, filter by author, restrict history to a file, and attribute lines to historical commits.
Key Takeaways
  • Git log can filter history by author, message, date, and path.
  • git blame is a historical attribution tool.
  • Inspect the associated commit to understand why a line was introduced.
Knowledge Check

What is `git blame` primarily used for?