⚡ ~/naveed Interview Prep
⚡ Portfolio Home ✍️ Engineering Blog Deep Dives 🎯 Interview Hub 1,000+ Scenarios ☸️ Kubernetes Mastery Hub 24 Modules 🎮 DevOps Arcade & Quizzes Subnet Blitz ⚡ 🗺️ DevOps Roadmaps PDFs & Guides 🤖 Morpheus Analysis AI Quant ↗ 🛠️ Developer Tools Utilities 🧪 Labs & Experiments 📄 Interactive CV & Certs 🔗 All Links & Socials ⚡ Join The Dispatch (Weekly SRE Newsletter) →
← Back to All Git & Branching Workflows Interview Questions Scenario 52 of 52 in Git & Branching Workflows
Senior Cloud Engineer (L2) Git Branching Workflows & Cherry-Pick L2 Cloud Screen

Q: You have specific code changes in one Git branch and want to move only those changes to another branch. How would you do this?

Production guide for selectively porting isolated commits and hotfixes between Git branches using git cherry-pick without merging unrelated code.

#Git #Branching #Cherry-Pick #Hotfix #Merge Conflicts #Version Control
🎙️ Candidate Opening & Architectural Context
"When you need to backport a specific bug fix, configuration change, or feature from a development or experimental branch into a release or production hotfix branch without merging the entire history, `git cherry-pick` is the standard tool. It extracts the diff introduced by specific commits and applies them as new commits onto the target branch."
Advertisement
⚡ Recommended Practice Lab

Want to master this scenario in a live sandbox? KodeKloud's Advanced Git Workflows, Rebase & Interactive Diagnostics covers this exact problem with hands-on terminal drills.

🛠️ Production Runbook & Step-by-Step Resolution

1

Identify Commit Hash on Source Branch

Check the git log on the source branch to identify the exact commit SHAs you want to copy.

git checkout feature-branch
git log --oneline -n 5
# Output: a8f3b9c fix(auth): resolve token expiration race condition
2

Switch to Target Branch and Execute Cherry-Pick

Switch to the target branch (e.g. `main` or `release-v1.4`), ensure your working tree is clean, and run `git cherry-pick `.

git checkout main
git pull origin main
git cherry-pick a8f3b9c
Advertisement
3

Resolving Merge Conflicts (If Applicable)

If the destination branch has divergent code, Git will pause with conflict markers. Resolve conflicts in your editor, stage the files, and continue the cherry-pick.

# Check conflicting files
git status
# After resolving markers:
git add auth/token.go
git cherry-pick --continue
# (Or run 'git cherry-pick --abort' to cancel cleanly)
4

Cherry-Picking Multiple Commits or Ranges

To cherry-pick a contiguous range of commits from commit A to commit B: `git cherry-pick A^..B` (includes commit A up to commit B).

Pro Tip: Production Best Practice: Always run unit tests after cherry-picking before pushing to remote, as dependencies from the source branch may be missing in the target branch.
💡 The Senior SRE Gold Nugget (Key Architectural Takeaway)
"Use 'git cherry-pick <commit-sha>' to apply specific commits onto a target branch without merging whole branches. Resolve conflicts if divergence occurs and run test suites before pushing."
⚡ 60-Second Elevator Pitch Talking Points
  • Identify the commit SHA from git log on the source branch.
  • Checkout the target branch and run git cherry-pick <commit-sha>.
  • If conflicts occur, resolve conflict markers, stage changes, and run git cherry-pick --continue.
  • Use git cherry-pick A^..B to port a contiguous range of commits cleanly.
Advertisement
Want more Git & Branching Workflows scenarios?
Explore our complete collection of scenario-based Git & Branching Workflows interview runbooks.
Browse All Git & Branching Workflows Questions →