tags:

views:

291

answers:

4

So, I have a maintenance branch and a master branch in my project. If I make a commit in the maintenance branch and want to merge it forward to the master branch, that's easy:

git checkout master; git merge maintenance

But if I want to go the other way around, i.e. apply a commit made to master back to my maintenance branch, how do I do that? Is this considered cherry-picking? Will it cause problems or conflicts if I merge the maintenance branch forward again?

+4  A: 

This is exactly the use case for git-cherry-pick

git checkout maintenance
git cherry-pick <commit from master>
mwalling
A: 

Yes, it is considered cherry-picking and no, generally it should not introduce problems. If commit doesn't apply cleanly when backporting you may face exactly same conflict when cherry-picking it back.

Michael Krelin - hacker
A: 

As a general rule, I use merge to move changes "up" the tree (from maintenance to master) and rebase to move them "down" the tree (from master to maintenance). This is so the order of commits in the master branch is maintained.

Rebase essentially rolls back all your changes on the current branch to the fork (or last rebase), copies over newer changes and then re-applies your changes.

If you don't want to get all changes from the master, then you will probably need to cherry pick the ones you want.

Brenton Alker
I wondered about *rebase* too. But presuming a _maintenance_ branch exists specifically to _not_ have all the current changes then that isn't what you want. It seems best to me to rebase a development branch, but cherry-pick a bug fix made in master (or any upstream development branch) back to maintenance.
Alex Stoddard
+3  A: 

Alternate solution to using "git cherry-pick" (as recommended in other responses) would be to create a separate [topic] branch for the fix off maintenance branch, and merge this branch first into maintenance branch, then into master branch (trunk).

This workflow is (somewhat) described in Resolving conflicts/dependencies between topic branches early blog post by Junio C Hamano, git maintainer.

Jakub Narębski