Methods for Calculating Monthly Commit Days in Git Repositories

To determine the number of days with commits in a specific month for a Git repository, various command-line approaches can be used depending on the environment.

Using Git Bash for Unix-like Systems

Navigate to the local Git repository directory in Git Bash. Execute the following command to count commit days for a given month, such as February 2024:

git log --pretty=format:'%ad' --date=format:'%Y-%m-%d' | grep '^2024-02' | sort -u | wc -l

This pipeline extracts commit dates in YYYY-MM-DD format, filters lines starting with the specified month, sorts unique dates, and outputs the count.

Using Windows PowerShell

In PowerShell, a similar result can be achieved with:

git log --pretty=format:'%ad' --date=format:'%Y-%m-%d' | Select-String -Pattern '2024-02' | Get-Unique | Measure-Object | Select-Object -ExpandProperty Count

Here, the command selects lines matching the month pattern, removes duplicates, and calculates the total unique antries.

Including All Branches

To incorporate commits from all branches, add the --all flag. For example, in PowerShell:

git log --all --pretty=format:'%ad' --date=format:'%Y-%m-%d' | Select-String -Pattern '2024-02' | Get-Unique | Measure-Object | Select-Object -ExpandProperty Count

Replace '2024-02' with the desired year and month in YYYY-MM format. The components function as follows:

  • --all: Includes commits from every branch.
  • --pretty=format:'%ad': Outputs only the author date.
  • --date=format:'%Y-%m-%d': Formats the date consistently.
  • Select-String -Pattern '2024-02': Filters commits too the specified month.
  • Get-Unique: Groups by distinct dates.
  • Measure-Object with Select-Object: Counts the unique dates, representing days with commits.

Tags: Git Version Control statistics Command Line bash

Posted on Tue, 13 Oct 2026 16:53:31 +0000 by reli4nt