Last active
January 27, 2026 08:49
-
-
Save Yohn/164f9912efa5dda36c10ab579716195c to your computer and use it in GitHub Desktop.
Find a Github repo on your Windows PC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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