3. Collaborating on GitHub

Git Stash, History Inspection & Tags

Pause unfinished work cleanly with git stash, find which commit changed a line using git log and git blame, and mark release versions with Git tags.

3 min readUpdated 2026-11-29
In This Lesson
  • Pause unfinished work cleanly using git stash push and git stash pop
  • Search commit history and file changes with git log and git blame
  • Mark release milestones permanently using annotated Git tags

Real software work rarely happens in one straight line. Often you are halfway through editing 3 files when an urgent bug pops up on another branch—or you notice a strange line of code and wonder when and why it was written.

Pausing Unfinished Work with git stash

Suppose your files are messy and half-finished—not ready for a real commit—yet you need to switch to main right now.

Think of git stash like putting your current papers into a temporary desk drawer so your desk looks spotless again:

bash
git stash push -m "wip: mobile menu styling"   # Put edits into the stash drawer
git stash list                                  # Peek at all saved stash entries
git stash show -p stash@{0}                     # Preview exact diff inside a stash
git stash pop                                   # Restore latest stash AND remove it
git stash apply                                 # Restore edits WITHOUT removing from drawer
Include Brand-New Untracked Files

By default, git stash saves edits to files Git already tracks. Add -u (git stash push -u) if you also want to stash newly created untracked files.

Investigating History (git log, git show & git blame)

Git's history isn't just for backups—it is a searchable detective tool when debugging why something changed:

bash
# Search commit messages for a keyword
git log --oneline --grep="quiz"

# Search commit diffs for WHEN a specific function or variable was added/removed
git log -S "formatMb" --oneline

# See the last 3 commits (with exact diffs!) that touched one specific file
git log -p -n 3 src/components/Header.tsx

# Inspect one exact commit by SHA
git show a1b2c3d

# See which commit last edited each line in a file
git blame src/lib/site.ts

Copying One Fix with git cherry-pick

Sometimes a critical bug fix lands on a feature branch (say commit 9f4c21a), and you need just that single commit on main right now without merging the rest of the unfinished feature:

bash
git switch main
git cherry-pick 9f4c21a

Git applies the exact diff of 9f4c21a onto main as a fresh commit, leaving the rest of the feature branch untouched.

Marking Releases with Annotated Tags (git tag)

Branches move forward as you add commits, whereas a tag pins a permanent version label (following Semantic Versioning: MAJOR.MINOR.PATCH, like v1.2.0) onto one exact snapshot so you can always reference or redeploy that release:

bash
git tag -a v1.2.0 -m "Release v1.2.0: interactive quizzes and SQL sandbox"
git push origin v1.2.0
Lightweight vs Annotated Tags

Always prefer annotated tags (git tag -a v1.2.0 -m "...") for releases—they store the tagger name, date, and release message, whereas lightweight tags are just bare pointers.

Quick Checkpoints

Check Your Understanding

You have uncommitted edits on your branch and need to temporarily set them aside to switch branches cleanly. Which command helps?

Check Your Understanding

Which command searches Git history to find which commit added or removed a specific symbol like useCourseProgress?