On Thursday, January 17, 2013 6:31:31 AM UTC+1, Jeenu wrote:

> I wanted to find out names of downstream branches from a given current 
> branch, from the command line. I think there should be a way to find this, 
> as gitk already lists downstream branches.
> If I rebase subsystem branch S of master M, and all topic branches Tn 
> based on S would have be rebased again manually. For that it'd be helpful 
> to know all Tn given an S, without manual or visual examination.
What's a downstream branch? And how do you list them with gitk?

Anyhow, I'll assume that you are asking how to get a list of all branches 
that have *the tip* of branch X as an ancestor. I'm not sure if this is 
what you actually want though.

You can see all your local branches with `git branch`.

Now you want for each of these, to see if X is included among their 
ancestors. Let's say they are A, B, C, while D is not an ancestor of X.

The quickest way I can think of at the moment to check that (although there 
probably are more elegant ways), is to just check if the common ancestor of 
X and the branch in question:

1) git merge-base X A -> this outputs the SHA value of the common ancestor 
of A and X
2) git rev-parse A -> this outputs the SHA value of A
3) If the output of the two commands above are the same, then A is an 
ancestor of X.

Or, to put it in bash: 

if [ `git merge-base X A` \=\= `git rev-parse A` ]; then echo "found 
ancestor"; fi

4) Repeat for all branches (or script it)

Bear in mind that when A gets some more commits, the above doesn't work any 
more. You then have to find the common ancestor of A and X first, and see 
in which branches the ancestor is contained, maybe using git branch 

Interestingly enough, the docs on git 
this, which relates to your problem:

   --contains <commit> is used to find all branches which will need special 
attention if <commit> were to be rebased or amended, since those branches 
contain the specified <commit>.


Reply via email to