Skip to content

GitHub Commands - Check Repo Sizes in an Organization

List of References (Click to expand)
  1. Create a GitHub Personal Access Token (PAT):
  2. Go to GitHub → Settings → Developer settings → Personal access tokens.
  3. Create a Fine‑grained token with at least read‑only repo scope.
  4. If your org enforces SSO, click Authorize for your org after creating the token.
  5. Copy the token (it looks like ghp_xxxxx...).

    image

  6. Store the Token in PowerShell:

    $env:GITHUB_TOKEN="ghp_yourtokenhere"
    
  7. Call the GitHub API: Run PowerShell script that lists all repos in your org with their sizes. Please change {YOUR-ORG-NAME}

    In GB

    $headers = @{ Authorization = "token $env:GITHUB_TOKEN" }
    $response = Invoke-WebRequest -Uri "https://api.github.com/orgs/{YOUR-ORG-NAME}/repos?per_page=100" -Headers $headers
    $repos = $response.Content | ConvertFrom-Json
    
    # Show name and size in GB
    $repos | Select-Object name, @{Name="SizeGB";Expression={[math]::Round($_.size/(1024*1024),2)}} | Sort-Object SizeGB -Descending
    

    E.g in GB:

    image

    In KB:

    $headers = @{ Authorization = "token $env:GITHUB_TOKEN" }
    $response = Invoke-WebRequest -Uri "https://api.github.com/orgs/{YOUR-ORG-NAME}/repos?per_page=100" -Headers $headers
    $repos = $response.Content | ConvertFrom-Json
    
    # Show name and size in MB
    $repos | Select-Object name, @{Name="SizeMB";Expression={[math]::Round($_.size/1024,2)}} | Sort-Object SizeMB -Descending
    

    E.g in KB:

    image