1

I have many branches, some of which are remnants of pull requests, others are temporary local branches.

How do I list all the branches that dangle, i.e. are leafs in the git tree?


Here is an illustration of what I want, yet the solutions below do not give:

  B
 / \
A-C-D
 \
  E-F

With this branch layout I want a list like:

  • D
  • F

These questions do not answer my problem, yet some come close:

tensor
  • 41
  • 2
  • 10
  • https://github.com/seschwar/git-heads ? – Mikhail Jul 14 '20 at 17:23
  • Does this answer your question? [How do I get the list of branches not merged into master, ordered by most recent commit?](https://stackoverflow.com/questions/15577847/how-do-i-get-the-list-of-branches-not-merged-into-master-ordered-by-most-recent) – EncryptedWatermelon Jul 14 '20 at 18:04
  • @Mikhail git-heads only show the commits, not the branch names, at least in my testing. – tensor Jul 16 '20 at 11:20
  • @EncryptedWatermelon The answers show how to list branches not merged into a _specific branch_. This includes branches part of the stem. – tensor Jul 16 '20 at 11:22
  • Use `git branch --points-at` to find branches by commits – Mikhail Jul 16 '20 at 11:29
  • How do I use `--points-at` with `git-heads`? It uses `git log`. – tensor Jul 16 '20 at 11:33
  • Likely there is nothing built in, you will have to chain together multiple commands. A simple way to get started would be `git show-ref --heads`, this will output "HASH refs/heads/branchname" for each branch, and then you will have to pipe that through for instance SED to edit the lines. – Lasse V. Karlsen Jul 16 '20 at 11:49
  • Powershell solution: `git show-ref --heads | Foreach { $_.Split()[1] -replace "^refs/heads/","" }` – Lasse V. Karlsen Jul 16 '20 at 11:54
  • `git show-ref --heads` would, in my example list `A-F`, i.e. all branches – tensor Jul 16 '20 at 11:59
  • Hm, I found this in scripts I've used for something similar but I guess there must be more massaging in the rest of the scripts then. Ignore my comments then, other than the bit about nothing is built in. I don't think there is anything that will do what you want out of the box. – Lasse V. Karlsen Jul 16 '20 at 12:50
  • Something built in would be ideal. Then an elegant one-liner wold be the next-best. Lastly, a home cooked script/external program, would suffice. If you have any of these, I'll be happy to mark it as an answer, if it really works as described. – tensor Jul 16 '20 at 12:58

0 Answers0