0

Given I'm in "c:\", I want to see some basic info about git repos, which are located in subfolders of my current location. Branch name, origin and state (has changes or not) are enough. I'd highly appreciate a command or a script that does it. Here is the sample of output:

C:\folder1\.git
  https://origin.com/repo1.git
    = main

C:\folder2\folder\folder\.git
  https://origin2/
    = master

C:\folder3\.git
  https://origin3.com/_git/ProjectGo
    * features/feature1

C:\folder4\.git
  https://origin4.com/_git/ProjectNo
    = users/superman/bug-all-is-broken
Azamat S
  • 71
  • 1
  • 3

1 Answers1

0

// run it this way: .\script.ps1 5
// for searching subfolders 5 levels down only

param ([int] $depth=3)
$old = Get-Location
git --version
Write-Host "Searching folders...";
Get-ChildItem -Recurse -Depth $depth -Directory -Force -Filter ".git" |
ForEach-Object {
    $path = $_.FullName
    Set-Location($_.FullName)
    $origin = git remote get-url origin
    $branch = git branch --show-current
    Set-Location($_.FullName + "\..\")
    $uncommitted = git status -s
    Write-Host "$path" -ForegroundColor DarkGray;   
    Write-Host "  $origin" -ForegroundColor DarkCyan;   
    if ($uncommitted) {
        Write-Host "    * $branch" -ForegroundColor DarkRed;
    } else {
        Write-Host "    = $branch" -ForegroundColor DarkGreen;
    }
    
    Write-Host "";
}

Set-Location($old)

sample output:

output

Azamat S
  • 71
  • 1
  • 3