windows:git:generate-clone-script-to-include-all-origins-from-all-repos-from-current-dir
Table of Contents
Generate clone.bat Script
This page provides a PowerShell script to automatically generate a `clone.bat` file for cloning multiple Git repositories.
PowerShell Script
- generateCloneScript.ps1
# PowerShell script to generate clone.bat # Get all directories in the current path $directories = Get-ChildItem -Directory # Initialize the clone.bat content $cloneScriptContent = "@echo off`n" foreach ($dir in $directories) { # Check if the directory is a Git repository if (Test-Path "$($dir.FullName)\.git") { # Get the remote origin URL $remoteUrl = git -C $dir.FullName remote get-url origin # Add the git clone command to the script content $cloneScriptContent += "git clone $remoteUrl`n" } } # Write the content to clone.bat Set-Content -Path "clone.bat" -Value $cloneScriptContent Write-Host "clone.bat script generated successfully."
How to Run the Script
1. Save the Script: Save the above PowerShell script to a file named `generateCloneScript.ps1`.
2. Open PowerShell as Administrator:
- Search for “PowerShell” in the Start menu.
- Right-click on “Windows PowerShell” and select “Run as administrator”.
3. Change the Execution Policy:
- Run the following command to allow script execution:
Set-ExecutionPolicy RemoteSigned
- Confirm the change by typing `Y` and pressing Enter.
4. Navigate to the Parent Directory:
- Use `cd` to navigate to the directory containing all the repositories.
5. Run the Script:
- Execute the script by running:
.\generateCloneScript.ps1
6. Check the Output:
- A `clone.bat` file will be generated in the same directory, containing the `git clone` commands for each repository.
- The `RemoteSigned` policy allows scripts created on your local machine to run, but requires that scripts downloaded from the internet be signed by a trusted publisher.
- You can revert the execution policy to its default setting by running:
Set-ExecutionPolicy Restricted
This page provides a comprehensive guide to generating and running the script.
windows/git/generate-clone-script-to-include-all-origins-from-all-repos-from-current-dir.txt · Last modified: 2024/09/30 14:15 by odefta