From my experience, cherry pick is undesirable for the following reason:
- cherry-picking is a signal you are about to do something that is not part of normal code flow, so treat it as "at your own risk"
1)
In normal everyday use, you should avoid randomly bringing in commits from other feature branches because if some code has not reached the main branch (dev, master, trunk - whichever, depends on your branching strategy) then, most probably, the code is not mature enough. It has not passed a merge request, has not been validated by code reviewers etc.
So, when you bring in some foreign code, you become responsible for it.
When you later create a merge request to integrate your branch into the main, code reviewers will treat all the code as yours. Then you'll have to make excuses "yeah, but that's not my code, a colleague wrote it, I just borrowed it". No way. You are now responsible for it.
And also, later when the same code comes in as a merge request from the original branch, it will have to be reviewed by someone. Now you have the same code being validated twice. It's a waste of time.
Be patient, wait for some feature to become stable and reach the main branch, so that you can pull it into your branch without becoming responsible for it.
2)
Sometimes there are situations when you are forced by somebody to use cherry-picking. For example, some manager says: "We need this fix from that branch right now, but we don't need any other changes; please, pick it and merge it into our new hotfix branch". Then it becomes their decision and their responsibility to deal with the consequences. Make it clear to them that they are violating your normal code flow.
An alternative to picking urgent fixes from dev into master is to create a new hotfix branch from the last released tag, fix the issue there, test it, release the hotfix and only then merge the hotfix up into dev.
Why so? Because if you fix the issue in dev first and then cherry-pick it into master, there is some risk that dev branch has some critical code changes that would make the fix incompatible with the master. So, after a cherry-pick you might end up rewriting the entire fix specifically for the master/release branch.
I have been in this situation many times (oh, I'll just cherry-pick this fix from dev... crap, it doesn't even build on my very urgent hotfix branch, have to rewrite it).
Project managers want to release hotfixes sooner, they usually don't care much about development branches. Thus it makes more sense to implement a fix based on the stable release (master) branch, release the hotfix and only then merge it back into the main development branch (again, possibly having to rewrite the fix because it's incompatible with the latest changes in dev).
git cherry-pick
is a great command. In the typical software cycle, we have our dev branch and our release branches. As we encounter bugs in the release, we fix them on dev thencherry-pick
them over to release so that when we make a bug fix release, it's ready to go. Your use seems to be quite similar, but without knowing more about your code and how you test, I can't recommend a better git work flow. – Endwaysfeature1
as the upstream branch fortest-feature1
, and then rebasetest-feature1
wheneverfeature1
changes. Then for fixes that I find intest-feature1
I wouldcherry-pick
them down tofeature1
, or rebase them if there are a lot of commits to apply. – Symphysisgit
will have zero trouble with the handling of the changes it introduces. – Intoxicate