Functions/Sync-AllGitRepos.ps1
function Sync-AllGitRepos { [CmdletBinding()] param ( [Parameter()] [switch] $Pull, [Parameter()] [switch] $CommitAndPush, [Parameter()] [string] $GitFolder = "$($env:USERPROFILE)\Git" ) "---------------------------------" Get-ChildItem $GitFolder -Directory | ForEach-Object { $GitConfigPath = Join-Path $_.FullName ".git" if (Test-Path $GitConfigPath) { Set-Location $_.FullName Write-Host $_.Name -ForegroundColor Green "`n" git switch main git fetch --all git status if ($Pull) { git pull } if ($CommitAndPush) { git add . git commit -a -m 'Commit All' git push } "----------------------------`n" } } Set-Location $GitFolder } |