11

How can I get the total number remote branches in Git?

To get all the remotes branches, I do this statement below, but I cannot get the count/total of these branches. I tried --count, but it didn't work:

  git branch -r

How would I get just the count of these?

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
РАВИ
  • 10,413
  • 4
  • 28
  • 39
  • 2
    From Powershell v3 you can use the Count method on the result array, e.g. `(git branch -r).Count`. In Powershell v7.1 you also have the [Mesure-Object](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/measure-object?view=powershell-7.1) command for detail/control. – Aaron Dec 22 '20 at 21:02

2 Answers2

36

Something like

 git branch -r | wc -l

using a shell.

wc -l counts the number of line on its input.

Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
blue112
  • 46,589
  • 3
  • 43
  • 54
1

For PowerShell users (after all PowerShell is now also available cross-platform, not only on Windows), these are two commands giving you the remote branch count:

# Works in PowerShell before v3
(git branch -r | measure-object -line).Lines

# Works in PowerShell v3 or later
(git branch -r).Count
Peter Mortensen
  • 30,030
  • 21
  • 100
  • 124
Tore Aurstad
  • 2,584
  • 24
  • 18