0

I am trying to understand how many times I have pushed to a branch. I am not looking for the number of commits. Is there any way I can figure this out?

I think I need to use git rev-list --count but cannot figure out how to do the rest

The reason I am asking this is that I want to use it in github actinos

This question Github actions - How to get a build number that starts from 1 in each branch

Amin Ba
  • 1,603
  • 1
  • 13
  • 38
  • 2
    `I want to use it in github actinos` can you elaborate please on why number of _pushes_ is interesting to you? Please edit the question to address. – AD7six Mar 31 '23 at 18:10
  • 3
    Please don’t create multiple post for the same question, but these both sound like an https://xyproblem.info/ – AD7six Mar 31 '23 at 18:23

1 Answers1

3

You can't see this on the repo itself. Only the hosting provider knows how many pushes have been made. In your local repo that metadata isn't available (and it might be different between different copies of the repo).

For example, Azure DevOps has a Pushes API. You can query it to grab the number of pushes.

In GitHub this push information is only available through the Audit API for GitHub Enterprise accounts. The REST API provides access to the git.push event category.

From your other questions I gather you want to use the number of pushes to define a version number. I'd recommend against it due to the fact that the number of pushes can change over time as repos are either force-pushed, forked or mirrored. Instead, rely on the number of commits, or explicitly tag commits and count the tags.

jessehouwing
  • 106,458
  • 22
  • 256
  • 341