Read more

Git: Advisory for cherry-picks to production branches

Tobias Kraze
May 02, 2011Software engineer at makandra GmbH

We often have a separate production branch that lags a bit behind the more cutting edge main branch. Sometimes you want to move some, but not all commits from main to production. This can be done with a git cherry-pick.

Illustration UI/UX Design

UI/UX Design by makandra brand

We make sure that your target audience has the best possible experience with your digital product. You get:

  • Design tailored to your audience
  • Proven processes customized to your needs
  • An expert team of experienced designers
Read more Show archive.org snapshot

However, this may lead to considerable pain later, since git does not understand the commits are actually "the same". Hazards are unnecessary and hard to resolve conflicts as well as incorrect auto-merges.

In order to avoid this, always merge the production branch back to the main after the cherry-pick. Even though this will make the cherry-picked commits appear twice in main, both branches will now have a common base again.

So the full workflow to move the AWESOME_COMMIT_SHA1 to production is:

git checkout production
git cherry-pick AWESOME_COMMIT_SHA1
git checkout main
git merge production

To make your future life easier, choose a slightly more verbose merge commit message than the default:

Merge branch 'production' after cherry-picking AWESOME FEATURE
Posted by Tobias Kraze to makandra dev (2011-05-02 18:48)