'How can I so a "cascading" merge from an upstream branch and pass the merge to all downstream branches with one command?
I got a "Parent" branch. Branch A is a branch of Parent, Branch B is a branch of Branch A and Branch C is a branch of Branch B:
------ Parent
\----Branch A
\------ Branch B
\------- Branch C
I want to merge some changes into Branch A and then pass those same changes onto Branches B and C. Is there a way this can be done easily? Perhaps I can use the --contains mechanism which lists the contained branches and do this with bash? I googled for a solution like that but didn't find one.
Solution 1:[1]
OK, I've done it with a crude post-commit hook in git hub written in perl. My branch naming convention allows me to do this based on branch names. There are a couple of little tricks needed to get output from the branch --list, namely turning a paging setting off and back on in git.
#!/usr/bin/env perl
use strict;
use warnings;
# get the current branch name
my $curr_branch = `git branch --show`;
chomp $curr_branch;
# get the names of all the branches that have this branch as parent and merge commit into each of them
if ($curr_branch eq 'configs') {
`git config --global pager.branch false`;
my $out = `git branch --list --no-color --no-column`;
`git config --global pager.branch true`;
my @list = grep { /\scfg_/ } split /\n/, $out;
foreach my $l ( @list ) {
print "Merging to $l\n";
`git checkout $l`;
`git merge --no-edit configs`;
}
}
`git checkout configs`;
I've symlinked the my unsued post-merge script to this post-commit script so it's also triggered on merges with another branch.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | StevieD |
