Question

I have the following tree:

branch1               G---H---I
                     /   
master       A---B---C---D---E---F
                          \
branch2                    M---N---O

I need to make some modifications in B. Is there any easy way to spread the modifications to all the branches (master, branch1 and branch2) ?

Was it helpful?

Solution

The safest way to do this is:

  1. Create a new branch from B

    git checkout -b BPRIME SHA_OF_B

  2. Make some changes, and commit them. you're graph will look like:

    BPRIME              B'
                       /  
    branch1           /   G---H---I
                     /   /   
    master       A---B---C---D---E---F
                              \
    branch2                    M---N---O
    
  3. Then cherry pick the commits from BPRIME to each of the branches.

    $ git checkout branch1 && git cherry-pick B'
    $ git checkout master && git cherry-pick B'
    $ git checkout branch2 && git cherry-pick B'
    

This is the safest option because you are not changing the history.

OTHER TIPS

Make the new commit in master branch and then rebase the other branches with the master.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top