Ch. 16 · Git & CI/CD

Git Cherry-Pick and Patch-Based Backports

Git Cherry-Pick and Patch-Based Backports. Learn the reasoning, a practical example, common mistakes and an interview exercise.

~2 min readbeginnerupdated Oct 3, 2026

Cherry-pick applies a commit’s change to another history, creating a new commit identity. It suits selected backports with understood dependencies.

Before you start

You should understand commits, branches, the working tree and the staging area. Draw the commit graph before changing history. Try commands in a disposable repository with a clean working tree so you can observe exactly which references and files each operation changes.

The practical goal is to reason through this situation: A bug fix can be backported to a maintenance branch without merging unrelated features. Read the walkthrough first, then try the interview exercise before opening its answer. The important part is explaining the decision and its consequences, rather than remembering a definition alone.

Step-by-step walkthrough

Step 1: Identify patch prerequisites

A selected fix may depend on APIs absent in maintenance code.

Step 2: Apply to the target history

The resulting commit has a new identity on that branch.

Step 3: Validate target behavior

Run checks using the target branch’s supported versions and assumptions.

Worked scenario

A bug fix can be backported to a maintenance branch without merging unrelated features.

A fix uses a helper introduced in a later feature release. Cherry-picking its patch onto the older branch may apply cleanly but fail compilation or behavior. Backport the necessary bounded prerequisites or adapt the fix; clean textual application is only the first check.

Common mistake

A clean application does not prove semantic compatibility.

Verify the behavior

Test the regression on the maintenance branch before and after the backport.

Interview exercise

Validate a backport.

Answer and reasoning

Check prerequisite changes, supported APIs and affected tests on the target branch rather than only on the original branch.

Continue learning

Compare the scenario with the Git and CI/CD interview questions and test your understanding with the Git and CI/CD MCQs. For terminology and implementation details, consult the reference material.

More in Git & CI/CD

read ✓Git & CI/CD · easy

Git Detached HEAD

What a detached HEAD is, when it happens, and how to keep commits made in that state.

~2 min readread →
read ✓Git & CI/CD · mid

Git Hooks and Local Automation

Automate checks with client and server hooks, share them through a framework, and enforce the same rules in CI where they cannot be bypassed.

~2 min readread →
read ✓Git & CI/CD · hard

Git LFS for Large Files

Track large binaries with Git LFS, keep pointer files in the repository, and plan for LFS storage and access.

~2 min readread →
esc