The first lessons covered how to make history. This one is about using it: finding the commit that broke Orbit, moving one fix between branches, learning why a line exists and working on two branches at once. These commands are what make an experienced Git user fast during an incident.
cherry-pick: copy one commit
git cherry-pick applies the changes of one commit on top of your current branch as a new commit. The classic use is back-porting a fix to a release branch:
$ git switch release/1.4
$ git cherry-pick 3e8a1f0
[release/1.4 b51c2d4] Fix crash when the note title is empty
$ git cherry-pick -x 3e8a1f0 # also note "(cherry picked from commit ...)" in the message
$ git cherry-pick a1b2c3d..f6e5d4c # a range of commits
Conflicts are handled like in a rebase: fix, git add, git cherry-pick --continue or --abort. Cherry-pick creates duplicate commits with different IDs, so prefer merging whole branches when you can, and keep cherry-picks for targeted fixes.
bisect: find the commit that broke it
Orbit’s search was fast in v1.3.0 and is slow now, 200 commits later. Instead of reading 200 commits, let Git do a binary search. Each step halves the range, so 200 commits take about 8 tests.
$ git bisect start
$ git bisect bad # the current commit is slow
$ git bisect good v1.3.0 # this release was fine
Bisecting: 99 revisions left to test after this (roughly 7 steps)
[4c2d...] Cache user preferences
$ npm run bench:search # test, then tell Git
$ git bisect good
$ ... # repeat until Git names the culprit
7f13a90 is the first bad commit
$ git bisect reset # back to where you started
If you can write a script that exits 0 for good and non-zero for bad, Git runs the whole search on its own:
$ git bisect start HEAD v1.3.0
$ git bisect run ./scripts/check-search-speed.sh
Git 2.56 added --reset-when-found to git bisect run, so the bisect session cleans up after itself as soon as the bad commit is found, instead of leaving you in the middle of the history. Exit code 125 from the script means “cannot test this commit, skip it”.
Tip: Bisect works best with small commits that each build and pass tests. That is one more reason to keep commits focused (lesson 3) and to fix them up before merging (lesson 6).
blame: why is this line here?
git blame shows, for each line of a file, the last commit that changed it:
$ git blame -L 10,15 server.js
7f13a90a (Bruno Lima 2026-10-02 14:11:09 -0300 10) const cache = new Map();
90bd114e (Ana Souza 2026-09-12 09:40:51 -0300 11) const port = process.env.PORT ?? 8080;
$ git show 7f13a90a # the commit, its message and the whole change
The point is not to find someone to blame, it is to find the context: the commit message and the pull request that explain why the line exists.
Useful options:
-wignores whitespace changes, and-Cfollows lines moved or copied from other files.--ignore-rev <commit>skips a commit, typically a mass reformat. List such commits in a.git-blame-ignore-revsfile and setblame.ignoreRevsFileso everyone benefits; GitHub’s blame view reads that file too.- Git 2.53 added
--diff-algorithmto blame, so it can use the same algorithm (for examplehistogram) as your diffs.
Searching history
git log can search the content of changes, not just messages:
$ git log -S "LOGIN_TIMEOUT" --oneline # commits that added or removed this string
$ git log -G "timeout\s*=\s*\d+" --oneline # commits whose diff matches a regex
$ git log --grep="ORB-142" --oneline # commits whose message mentions the issue
$ git log -L :handleLogin:server.js # the full history of one function
$ git log --follow -- api/server.js # history of a file across renames
-S (the “pickaxe”) is how you find when a configuration key appeared or disappeared. -L follows a function or a line range through every commit that touched it. Since Git 2.54, -L also works together with -S, -G and --word-diff, and Git 2.56 made --follow more reliable on histories with many merges.
git last-modified (Git 2.52)
Repository browsers show the last commit next to every file in a folder. Git 2.52 added a command that computes this efficiently:
$ git last-modified -- deploy/
It prints, for each path, the ID of the most recent commit that touched it, followed by the path. It is much faster than running git log -1 once per file, which matters in scripts and on large folders.
worktree: two branches at once
A worktree is an extra working folder attached to the same repository, with a different branch checked out. You can review a colleague’s PR or fix a production bug without stashing or committing half-done work:
$ git worktree add -b fix/ORB-150 ../orbit-hotfix origin/main
$ cd ../orbit-hotfix # a full checkout, sharing the same .git data
$ git commit -am "Fix ORB-150" && git push -u origin fix/ORB-150
$ cd ../orbit
$ git worktree list
/home/ana/orbit 90bd114 [feature/search]
/home/ana/orbit-hotfix c1d2e3f [fix/ORB-150]
$ git worktree remove ../orbit-hotfix
A branch can be checked out in only one worktree at a time. Worktrees share history and objects, so they are fast to create and use little disk compared with a second clone.
sparse checkout: only the folders you need
In a monorepo with hundreds of services, you may only need two folders. Sparse checkout limits the working tree to the paths you choose:
$ git clone --filter=blob:none --sparse https://github.com/orbit-dev/platform.git
$ cd platform
$ git sparse-checkout set services/orbit-api deploy/helm
$ git sparse-checkout list
$ git sparse-checkout clean # Git 2.52: remove leftover files outside the chosen paths
$ git sparse-checkout disable # back to everything
Combined with a blobless partial clone (lesson 7), only the content you check out is downloaded.
Keeping big repositories fast
$ git maintenance start # schedule background maintenance for this repository
$ git count-objects -vH # how big is the object database?
git maintenance runs tasks such as prefetching, commit-graph updates and repacking on a schedule. Since Git 2.54, its default strategy repacks geometrically, which keeps large repositories fast without long full repacks. On Linux, Git 2.55 also added the built-in file system monitor, which makes git status much faster in huge working trees (lesson 15).
Quick reference
| Task | Command |
|---|---|
| Copy one commit to this branch | git cherry-pick -x <commit> |
| Start a bisect | git bisect start <bad> <good> |
| Automatic bisect with cleanup (2.56) | git bisect run --reset-when-found <script> |
| Who changed these lines and why | git blame -w -C -L 10,20 <file> |
| When did this string appear | git log -S "text" |
| History of a function | git log -L :function:file |
| Last commit for each path (2.52) | git last-modified -- <path> |
| Second working folder | git worktree add <path> <branch> |
| Only some folders | git sparse-checkout set <paths> |
| Background maintenance | git maintenance start |
Exercise
Orbit’s tests pass on v1.3.0 and fail on main, 300 commits later. You have a test script. What is the fastest way to find the commit that broke them?
Show answer
Answer: D. Bisect performs a binary search: about nine test runs for 300 commits. With git bisect run, Git checks out each candidate and runs the script for you.
Exercise
A security fix was merged to main. The release/1.4 branch still runs in production and needs that single commit. What do you use?
Show answer
Answer: C. Cherry-pick copies just that commit’s changes onto the release branch. Merging main would bring every new feature along. -x records which commit it came from.
Exercise
You need to know which commit removed the setting MAX_UPLOAD_MB from the code. Which command finds it?
Show answer
Answer: B. -S finds commits whose changes add or remove the given string, including the one that deleted it. blame only shows lines that still exist, and –grep searches commit messages, not code.
Key takeaways
cherry-pickcopies single commits, ideal for back-porting fixes to release branches.git bisectfinds a breaking commit by binary search;bisect runautomates it and--reset-when-found(2.56) cleans up.blamegives context for a line; ignore formatting commits with.git-blame-ignore-revs.log -S,-G,-Land--followsearch the content of history;git last-modified(2.52) lists the last commit per path.- Worktrees, sparse checkout and
git maintenancekeep parallel work and large repositories manageable.
FAQ
Is cherry-picking bad practice?
No, but overusing it is. Each cherry-pick duplicates a commit, which can confuse later merges and history. Use it for targeted fixes on release branches, and merge branches for everything else.
What if a commit in the bisect range does not build?
Run git bisect skip and Git picks a nearby commit. In an automated run, make the script exit with code 125 for “cannot test”, and Git skips that commit.
How is a worktree different from a second clone?
A worktree shares the object database and configuration with the main repository, so it is created in seconds, uses little disk and sees new commits immediately. A second clone is fully independent and must fetch separately.
How do I stop blame from pointing at the commit that reformatted everything?
Add that commit’s full ID to .git-blame-ignore-revs, commit the file and set git config blame.ignoreRevsFile .git-blame-ignore-revs. Blame then looks past it to the commit that really changed each line.
When does sparse checkout make sense?
In large monorepos where you work in a few folders. It shrinks the working tree, speeds up git status and, with a partial clone, avoids downloading content you never use. In small repositories it adds complexity for no gain.