Cherry-Pick Is Cross-Database INSERT…SELECT

Sometimes you don’t want to merge an entire branch. You want one specific commit from another branch — one fix, one change, one feature — without bringing everything else along for the ride.

DBAs do this all the time. You’ve got a stored procedure fix in dev, but the full dev branch has 20 other changes that aren’t ready for production. You don’t deploy the whole branch. You extract just the fix you need.

In SQL Server, that’s INSERT...SELECT across databases — pulling specific rows from one database into another. In git, that’s cherry-pick.

A woman chef carefully selecting a single dish from one full buffet table and transferring it with tongs to another table, ignoring the rest of the dishes.

How Cherry-Pick Works

Cherry-pick copies a single commit from one branch and applies it to your current branch. The original commit stays where it is. You get a new commit on your branch with the same changes but a different SHA.

That’s it. The changes from commit a1b2c3d are now applied to main as a new commit. Everything else on the dev branch stays on the dev branch.

The DBA Analogy

You’re not copying the entire Development database. You’re selecting exactly the rows (commits) you need and inserting them into Production (your current branch).

Cherry-Picking Multiple Commits

Need more than one commit? You can cherry-pick a range:

When Cherry-Pick Gets Complicated

Cherry-pick can hit conflicts — just like merge conflicts. If the commit you’re picking depends on changes that don’t exist in your current branch, git can’t apply it cleanly.

When this happens:

This is the same problem you’d hit trying to INSERT...SELECT a row that has a foreign key dependency on a row that doesn’t exist in the target database. The data doesn’t stand alone — it has dependencies.

The Risks of Cherry-Picking

Cherry-pick is useful, but it creates a specific problem: duplicate changes.

When you cherry-pick a commit, the original still exists on the source branch. Later, when you merge that branch, git might see the same change applied twice. Modern git is usually smart enough to handle this, but it can cause confusing conflicts.

It’s like inserting a row via INSERT...SELECT and then later doing a full database restore from the source. Now you have the same data from two different paths, and you need to reconcile duplicates.

Best practice: Cherry-pick for hotfixes and emergencies. For planned work, prefer merging the whole branch when it’s ready.

The Hotfix Workflow

Here’s the most common cherry-pick scenario for DBAs working with SSDT or other database projects:

Notice how we combined cherry-pick (Post 8) with tags (Post 7)? The concepts build on each other.

Cherry-Pick vs. Merge vs. Rebase

Merge: Combine entire branch histories. Use for planned integration of completed features.

Rebase: Replay your commits on a new base. Use for keeping your branch up to date.

Cherry-pick: Copy a specific commit. Use for emergency hotfixes or extracting one change from a larger body of work.

Each one is a different type of data movement, just like INSERT...SELECT, database restore, and log shipping are all different ways to move data between SQL Server instances — each appropriate for different scenarios.

Try This Yourself

The One Sentence to Remember

Cherry-pick is INSERT...SELECT across branches — extract exactly the commits you need without merging everything else.

Previously: Tags Are Database Snapshots You Can Name
Next up: Git for SSDT Projects: Where It All Comes Together

Got questions? Find me on Bluesky or LinkedIn.