Free 40-page Claude guide — setup, 120 prompt codes, MCP servers, AI agents. Download free →
CLSkills
Git & Version Controlintermediate

Cherry Pick Guide

Share

Help cherry-pick commits across branches safely

Works with OpenClaude

You are a Git workflow expert. The user wants to safely cherry-pick specific commits from one branch to another while avoiding conflicts and maintaining commit integrity.

What to check first

  • Run git log --oneline <source-branch> to identify the exact commits you want to cherry-pick
  • Run git status to ensure your working directory is clean before starting
  • Run git branch -a to confirm both source and target branches exist and are up-to-date

Steps

  1. Fetch the latest changes from remote with git fetch origin to ensure both branches are current
  2. Check out the target branch where commits will be applied: git checkout <target-branch>
  3. Identify the commit hash(es) from git log <source-branch> — copy the full SHA or use shorthand (e.g., a1b2c3d)
  4. Run git cherry-pick <commit-hash> for a single commit, or git cherry-pick <hash1> <hash2> <hash3> for multiple commits in order
  5. If conflicts occur, Git will pause and mark conflicted files — resolve them in your editor, then run git add <resolved-file>
  6. Continue the cherry-pick process with git cherry-pick --continue after resolving conflicts
  7. Verify the commits were applied correctly with git log --oneline -n 5 to see the new commits on your branch
  8. Push to remote with git push origin <target-branch> once you're satisfied with the result

Code

#!/bin/bash
# Cherry-pick commits safely with conflict handling and verification

SOURCE_BRANCH="${1:-main}"
TARGET_BRANCH="${2:-develop}"
COMMITS=("${@:3}")

# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m'

# Ensure clean working directory
if ! git diff-index --quiet HEAD --; then
    echo -e "${RED}Error: Working directory is not clean. Commit or stash changes first.${NC}"
    exit 1
fi

# Fetch latest from remote
echo -e "${YELLOW}Fetching latest changes...${NC}"
git fetch origin

# Switch to target branch
echo -e "${YELLOW}Checking out $TARGET_BRANCH...${NC}"
git checkout "$TARGET_BRANCH" || exit 1
git pull origin "$TARGET_BRANCH"

# Cherry-pick commits
for commit in "${COMMITS[@]}"; do
    echo -e "${YELLOW}Cherry-picking $commit...${NC}"
    
    if git cherry-pick "$commit"; then
        echo -e "${GREEN}Successfully cherry-picked $commit${NC}"
    else
        echo -e "${RED}Conflict detected in $commit. Resolve manually.${NC}"
        git status
        read -p "Press enter once conflicts are resolved: "
        
        if git cherry-pick --continue; then

Note: this example was truncated in the source. See the GitHub repo for the latest full version.

Common Pitfalls

  • Treating this skill as a one-shot solution — most workflows need iteration and verification
  • Skipping the verification steps — you don't know it worked until you measure
  • Applying this skill without understanding the underlying problem — read the related docs first

When NOT to Use This Skill

  • When a simpler manual approach would take less than 10 minutes
  • On critical production systems without testing in staging first
  • When you don't have permission or authorization to make these changes

How to Verify It Worked

  • Run the verification steps documented above
  • Compare the output against your expected baseline
  • Check logs for any warnings or errors — silent failures are the worst kind

Production Considerations

  • Test in staging before deploying to production
  • Have a rollback plan — every change should be reversible
  • Monitor the affected systems for at least 24 hours after the change

Quick Info

Difficultyintermediate
Version1.0.0
AuthorClaude Skills Hub
gitcherry-pickbranches

Install command:

curl -o ~/.claude/skills/cherry-pick-guide.md https://claude-skills-hub.vercel.app/skills/git/cherry-pick-guide.md

Related Git & Version Control Skills

Other Claude Code skills in the same category — free to download.

Want a Git & Version Control skill personalized to YOUR project?

This is a generic skill that works for everyone. Our AI can generate one tailored to your exact tech stack, naming conventions, folder structure, and coding patterns — with 3x more detail.