The article shares how using Git's cherry-pick
helped me apply specific IaC changes from a test
branch to master
without merging all changes, streamlining my workflow. It highlights the efficiency and simplicity of cherry-pick
in managing selective commits, reducing risks and conflicts.
I was working on some Infrastructure as Code (IaC) updates recently, and it was one of those days where everything felt more complicated than it should be. The test branch had a lot of changes, and while I needed just a few specific updates, the idea of pushing all of them to master seemed like a risky move. I really didn’t want to merge everything, especially since some parts of the code weren’t fully tested yet. But then, I remembered git cherry-pick.
It was like a lightbulb moment. Instead of doing a full branch merge, where I’d have to deal with a lot of unrelated changes and possibly break something, I could just pick out the exact commit I needed. That’s when I decided to cherry-pick the commit I wanted.
Here’s how it went down:
- I switched over to the master branch, pulled the latest changes, and then ran git log on the test branch to grab the specific commit hash I needed
git log test
- Now that you have the commit ID, you can apply it to the master branch with:
git cherry-pick <commit-hash>
-
Example: git cherry-pick abc1234
-
Resolve Any Conflicts (If Necessary)
-
Once the cherry-pick is complete and all conflicts are resolved (if any), push the updated master branch back to the remote repository:
git push origin master