Created
December 29, 2021 10:22
-
-
Save Cyclodex/332802d133b67a379fcd4e9a5841a69a to your computer and use it in GitHub Desktop.
Collects all git repositories and creates a clone script out of it
This file contains 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
$FILENAME = "clone-all-repos.ps1" | |
Write-Output "# extracted git clone commands" | Out-File -FilePath "$FILENAME" | |
Get-ChildItem . -Attributes Directory+Hidden -ErrorAction SilentlyContinue -Filter ".git" -Recurse | ForEach-Object { | |
$DIR_NAME = $_.Parent.Name | |
$DIR = Resolve-Path -Path $_.Parent.FullName -Relative | |
$GIT_DIR = "$DIR/.git" | |
Write-Output "" | Out-File -FilePath "$FILENAME" -Append | |
Write-Output "# $DIR_NAME" | Out-File -FilePath "$FILENAME" -Append | |
# Creates the folder structure | |
Write-Output "mkdir $DIR" | Out-File -FilePath "$FILENAME" -Append | |
# Clones the repository in the same folder | |
Write-Output "git clone $(git --git-dir=$GIT_DIR remote get-url origin) $dir;" | Out-File -FilePath "$FILENAME" -Append | |
# Add other remotes | |
$(git --git-dir=$GIT_DIR remote | Select-String -NotMatch "origin") | ForEach-Object { | |
Write-Output "git --git-dir=$GIT_DIR remote add $_ $(git --git-dir=$GIT_DIR remote get-url $_);" | Out-File -FilePath "$FILENAME" -Append | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Powershell script, converted from https://dev.to/douglaslise/how-to-migrate-all-your-git-repositores-to-a-new-computer-2c72