threads / discuss / 26648

1 patch to two branches

Subject: 1 patch to two branches

## tl;dr

2 messages between Mar 3, 2011 and Mar 7, 2011.

replies: 1people: 2as markdown or json

allstars· Mar 3, 2011, 12:46 UTC · lore

hi my case is as follows I have two branches basically they are the same, except they differ from different package name(java) and namespace(cpp) due to customer request

but now I have a fix , say a patch I want to commit it to both branches

but I am lazy so I just want to do just one 'git commit' and 'git push'

so I am thinking using a githook in remote server and each commit to branch A can also commit to branch B as well

but I am not quite sure what I should use in the hook
git rebase , git merge or git cherry pick ?

seems these 3 ways all lead to the same result but I dont know which is better and why

thanks
Neal Kreitzinger· Mar 7, 2011, 00:56 UTC · re: allstars · lore

Re: 1 patch to two branches

On 3/3/2011 6:46 AM, allstars wrote:
Show 20 quoted lines
> my case is as follows
> I have two branches
> basically they are the same, except they differ from different package
> name(java) and namespace(cpp) due to customer request
>
> but now I have a fix , say a patch
> I want to commit it to both branches
>
> but I am lazy so I just want to do just one 'git commit' and 'git
> push'
>
> so I am thinking using a githook in remote server
> and each commit to branch A can also commit to branch B as well
>
> but I am not quite sure what I should use in the hook
>
> git rebase , git merge or git cherry pick ?
>
> seems these 3 ways all lead to the same result
> but I dont know which is better and why

if by "patch" you mean git-am/git-apply then I'm afraid i don't have any suggestions because i don't use those commands. However, if you use git-push then have you thought about having a script on the local side that does something like this:

$ git checkout java-branch (hack hack) $ git add . $ git commit $ bash -v myscript <--run your script #!/bin/sh # script to commit java-branch head to cpp-branch and push them both git checkout cpp-branch && wait git cherry-pick java-branch && wait git push origin HEAD && wait git checkout java-branch && wait git push origin HEAD && wait exit 0

of course, you need some error checking in there. this is predicated on the assumption that the cherry-pick will not get any conflicts. if it does get conflicts then you will have to resolve them manually and that is a big reason to do this on the local side instead of the remote side.

v/r, neal

← back to recent threads