Git: How to reinstall many branches (with the same basic commit) at once?

I have a major affiliate in my project that I use to pull changes from other people. From this, I usually have several branches of topics that I currently work in.

My question is: is there a way for me to make new changes to my master, and then immediately return ALL of my threads to the topic?

In this situation:

D--E topic1 / A--B--C master \ F--G topic2 

And I want to do this with one single command (H came from the upstream):

                D '- E' topic1
               /
     A - B - C - H master
               \
                F '- G' topic2

Now I know that I can do this by reinstalling topic1 and topic2 to master, and I could even write a script to automate this. But what if I have several other branches, create new ones and often delete others, and I always get upstream changes?

This operation (several reinstallations), when done manually, is outdated and error prone.

Is there an easier way?

Thank!

+50
git git-rebase rebase
May 14 '09 at 10:36
source share
3 answers

I am sure there is no way to automatically do this. Remember that the “git rewrite wizard” can also return you to a shell that needs to resolve merge conflicts, so if you want to write a script to automate all of this, you need to take this into account.

You can pretty easily track which branches need updating. Hmm, for any branch, "git rev-list branch..master" will output if the branch is not updated in the top (i.e., it just ends on top). Thus, you need to go through all the local heads, except that the wizard for creating the report (nb "git show-branch" will do this approximately):

 git for-each-ref 'refs/heads/*' | \ while read rev type ref; do branch=$(expr "$ref" : 'refs/heads/\(.*\)' ) revs=$(git rev-list $rev..master) if [ -n "$revs" ]; then echo $branch needs update git diff --summary --shortstat -M -C -C $rev master fi done 

So, if you felt brave, you could replace this "git diff" with something like "git checkout $ branch & git master basase" (or maybe just "git pull - -rebase" if you installed it ) I think you will need to check the existence of the ".git / rebase-apply" directory or check the index for unrelated files ("git ls-files -u") to check if we have remained waiting for the merge.

Of course, if there are no conflicts, then it’s easy ... it creates something that also works when it’s not easy, that the problem is: p

And this does not necessarily apply to what happens if one of your branches is based on something else ... so I mentioned using git pull -rebase instead, because that would be rebase according to the branch configuration but not blindly from the master. Although the discovery is not based on the branch configuration ... perhaps it would be easiest to check each branch and make a "git pull" and allow the branch configuration to handle everything, including whether it needs to be reassembled or merged?

+17
May 14, '09 at 23:19
source share

You can always simply write a single-layer wrapper like this:

 for branch in topic1 topic2 topic3;do git rebase master $branch;done 

Since the branches of the ones you would like to reinstall will probably change over time, this is a quick and correct solution H ^ H ^ Hflexible :-)

+7
Dec 14 '11 at 17:18
source share

I turned this into a reliable script, contained in my git -extensions repository :

 $ git-urebaselocalbr --help Rebase all / the last committed N local branches (except for the current branch and master) to the updated upstream head. Usage: git-urebaselocalbr [--continue|--skip|--abort] [--branches "<branch1> ..."] [N] [-i|--interactive] [options] 
0
Sep 22 '16 at 12:47
source share



All Articles