Lesson 1.3:
Advanced Git Mastery
History as a Narrative
In high-velocity teams, Git history is a documentation tool. This lesson covers the advanced commands that keep your project's storyline clean and searchable.
Cherry-Picking Hotfixes
Sometimes you need a win from the future. cherry-pick allows you to grab specific commits from any branch without merging the noise.
# Grab a fix from the development branch into production
$ git checkout production
$ git cherry-pick [commit-hash]
The Binary Search: git bisect
When a phantom regression appears, use bisect to mathematically find the culprit.
$ git bisect start
$ git bisect bad HEAD # Current is broken
$ git bisect good v1.0.0 # This was fine
# Git jumps to the middle. You test.
$ git bisect good # or bad
# Repeat until the broken commit is revealed.
Automation with Git Hooks
Prevent errors before they are committed. We use Husky to run linters and test suites on every pre-commit.
// .husky/pre-commit
npm run lint
npm test -- --findRelatedTests
Check Your Knowledge
Which command allows you to grab a single commit from another branch?