0

My branching model for my project looks like this:

stable mainline git branching model

(source: https://www.bitsnbites.eu/a-stable-mainline-branching-model-for-git/)

I'm interested in knowing which release/* branch most recently split from the ancestry of a given commit (HEAD). For example, for the topmost master commit, this would be release/v1.1.

Is there a way to sort branches, e.g. with git branch --list release/* --sort=..., so that I can find the most recent merge-base?

I can always loop through all the branches and call git merge-base HEAD {branch} or something, but I'm curious if there is a way that's built in to git branch.

MHebes
  • 2,290
  • 1
  • 16
  • 29
  • 1
    Opinion - which is why it's not an answer - this could be better solved if you leveraged tags as opposed to branches. Tags are stateful and keep track of this information in a more manageable way as opposed to the tips of branches. – Makoto May 25 '22 at 18:44
  • @Makoto true, and I do use tags on the release branches themselves to track actual versions. I suppose I could tag the branching-off-point manually e.g. `v1.1.0-dev` and use `git-describe`, or I could change my question to be: "How do I do `git -c versionsort.suffix=- tag --list v* --sort=-v:refname` but only show tags that share a common ancestor with HEAD?" – MHebes May 25 '22 at 18:52
  • I will probably manually tag the branching-off point for now. Thanks for your input. – MHebes May 25 '22 at 18:53
  • There is nothing built in, and in fact solving the first sub-problem you want to solve can be hard: see [https://stackoverflow.com/questions/3161204/how-to-find-the-nearest-parent-of-a-git-branch](https://stackoverflow.com/q/3161204/1256452). Your constraints would change the sub-problem around, making some parts easier. – torek May 26 '22 at 07:27

0 Answers0