Skip to content

Instantly share code, notes, and snippets.

@guneysus
Created August 17, 2025 10:32
Show Gist options
  • Save guneysus/476e36cbfebaa4eefc17272a3fe57fb5 to your computer and use it in GitHub Desktop.
Save guneysus/476e36cbfebaa4eefc17272a3fe57fb5 to your computer and use it in GitHub Desktop.
Lists repos and some basic information. Needs posh-git
# Navigate to the base directory where your Git repositories are located
cd X:\git
# Initialize an empty array to store repository information
$repos = @()
# Iterate through each .git directory found up to 2 levels deep
ls *.git -Depth 2 | ForEach-Object {
$path = $_.FullName
# Write a debug message indicating the current repository being processed
# This message will only appear if Write-Debug is enabled (e.g., via $DebugPreference = 'Continue')
Write-Debug "Navigating $($path)"
# Get the current branch of the repository
# git -C $_.FullName ensures the command runs in the context of the repository
$branch = git -C $_ branch --show-current
# Get the URL of the 'origin' remote for the repository
$remote = $(git -C $_ config --get remote.origin.url)
git -C $_ push --all
# Get the status of the working directory (requires Write-VcsStatus function)
# Note: Write-VcsStatus is not a built-in PowerShell cmdlet.
# If this function is not defined in your environment, this line will cause an error.
# You might need to define or include a module that provides this function.
$status = cd $_.FullName | Write-VcsStatus
# Create a custom PowerShell object for the current repository's data
# This ensures that when the array is formatted as a table, these properties become columns.
$repoObject = [PSCustomObject]@{
Path = $path
Branch = $branch
Remote = $remote
Status = $status
FetchFailed = $fetchFailed
}
# Add the custom object to the $repos array
$repos += $repoObject
}
# Dump the array of repository objects as a formatted table
# -AutoSize adjusts column widths to fit content for better readability
$repos | Format-Table -AutoSize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment