Skip to content

Instantly share code, notes, and snippets.

@Yohn
Last active January 27, 2026 08:49
Show Gist options
  • Select an option

  • Save Yohn/164f9912efa5dda36c10ab579716195c to your computer and use it in GitHub Desktop.

Select an option

Save Yohn/164f9912efa5dda36c10ab579716195c to your computer and use it in GitHub Desktop.
Find a Github repo on your Windows PC
param(
[string]$SearchPath = "D:\local\directory\www\",
[string]$RepoUrl = "https://github.com/username/repo-to-find"
)
function Find-GitRepos {
param(
[string]$Path
)
# Get all items in current directory
$items = Get-ChildItem -Path $Path -Directory -ErrorAction SilentlyContinue
foreach ($item in $items) {
# Check if .git exists in this directory
$gitPath = Join-Path $item.FullName ".git"
if (Test-Path $gitPath) {
# Found a git repo - check its remote
Push-Location $item.FullName
$remoteUrl = git config --get remote.origin.url 2>$null
if ($remoteUrl) {
# Normalize URLs for comparison (remove .git suffix, handle both https and ssh)
$normalizedRemote = $remoteUrl -replace '\.git$', ''
$normalizedTarget = $RepoUrl -replace '\.git$', ''
# Also handle [email protected]: format
$normalizedRemote = $normalizedRemote -replace 'git@github\.com:', 'https://github.com/'
if ($normalizedRemote -eq $normalizedTarget) {
Write-Host "FOUND IT!" -ForegroundColor Green
Write-Host "Location: $($item.FullName)" -ForegroundColor Cyan
Write-Host "Remote: $remoteUrl"
Pop-Location
return $item.FullName
}
}
Pop-Location
# Don't recurse into this directory since we found .git
continue
}
# No .git here, recurse into subdirectories
$result = Find-GitRepos -Path $item.FullName
if ($result) {
return $result
}
}
}
Write-Host "Searching for repo: $RepoUrl" -ForegroundColor Yellow
Write-Host "Starting from: $SearchPath" -ForegroundColor Yellow
Write-Host ""
$found = Find-GitRepos -Path $SearchPath
if (-not $found) {
Write-Host "Repository not found." -ForegroundColor Red
}
@Yohn
Copy link
Author

Yohn commented Jan 27, 2026

Find local repo of github repository.

If you know you have a local install of a github repo but do not know where on your Windows system, put this script somewhere on your and update the top param() values with base directory to search in and the repo url.

Open powershell and go to the directory you have this file at and run:

.\find-repo.ps1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment