Git and Professional Development Workflow

Git Power Tools

bisect, cherry-pick, reset, and gitignore mastery

11 min read · Lesson 15 of 18

Beyond the Basics

These commands separate Git beginners from Git power users. Each one solves a specific problem you will definitely encounter.


git bisect: Finding When a Bug Was Introduced

git bisect performs a binary search through your commit history to find which commit introduced a bug:

git bisect start
git bisect bad              # Current commit has the bug
git bisect good abc1234     # This older commit was fine

Git checks out the midpoint commit. You test — is the bug present? Tell Git:

git bisect good  # or: git bisect bad

Git narrows the range and checks out another midpoint. In ~7 steps, you can find the exact commit among 100+ that introduced the bug. When done:

git bisect reset

git cherry-pick: Moving Individual Commits

cherry-pick applies a specific commit from one branch to another:

git checkout main
git cherry-pick a3f8c2d     # Apply this specific commit to main

Use cases: a hotfix was committed to a feature branch but needs to go to main immediately. Or you want one specific commit from a branch without merging everything else.


git reset: The Three Modes

git reset moves the branch pointer backward. The three modes differ in what happens to the changes:

  • --soft — Moves the branch pointer. Changes remain staged. Use when you want to redo a commit with different message or combine commits.
  • --mixed (default) — Moves the branch pointer. Changes go back to working directory (unstaged). Use when you want to re-stage selectively.
  • --hard — Moves the branch pointer. Discards all changes. Use with extreme caution. Recoverable via reflog.
git reset --soft HEAD~1    # Undo last commit, keep changes staged
git reset HEAD~1           # Undo last commit, keep changes in working dir
git reset --hard HEAD~1    # Undo last commit and DISCARD all changes
Never use git reset --hard on commits that have been pushed to a shared branch. Use git revert instead — it creates a new commit that undoes the changes, preserving history.

.gitignore Patterns

Common patterns you should know:

# Ignore specific file
.env

# Ignore directory
/vendor/
/node_modules/

# Wildcard — all .log files
*.log

# Negate — track this specific file even though *.log is ignored
!important.log

# Ignore in any subdirectory
**/cache/

# Ignore only in root directory
/storage/

If a file is already tracked, adding it to .gitignore won't remove it. You need to untrack it first:

git rm --cached .env       # Untracks without deleting the file

Key Takeaways

  • git bisect — Binary search for bug-introducing commits. Essential for large projects.
  • git cherry-pick — Apply individual commits across branches.
  • git reset--soft (keep staged), --mixed (keep unstaged), --hard (discard). Use --hard carefully.
  • .gitignore — Master patterns. Use git rm --cached to untrack already-tracked files.
Ask about this lesson