This PowerShell script allows you to download all branches from a GitHub repository into separate directories. Each branch will be saved in its own folder, making it easier to access and work with multiple branches independently.
- The script clones the specified GitHub repository without checking out any branches.
- It then iterates through each branch, checks it out, and copies the branch's contents to a corresponding directory.
- After processing all branches, the temporary repository is deleted, leaving behind only the folders containing the branches.
- Git: Ensure Git is installed and added to your system's PATH.
- PowerShell: The script is written for PowerShell, which is available by default on Windows.
Download the script file (DownloadGitBranches.ps1
) and save it to a location on your computer.
Open the script in a text editor and update the following variables:
$repoUrl
: Replace this with the URL of the GitHub repository you want to clone.$cloneDir
: Replace this with the directory where you want to save the branches.
-
Run PowerShell as Administrator:
- Open PowerShell as an Administrator by right-clicking on the PowerShell icon and selecting "Run as administrator".
-
Set Execution Policy (if needed):
- Temporarily allow running the script by entering:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass
-
Navigate to the Script Directory:
- Use
cd
to navigate to the directory where the script is saved.
- Use
-
Run the Script:
- Execute the script with the following command:
.\DownloadGitBranches.ps1
After the script completes, you will find a folder for each branch in the directory specified by $cloneDir
. Each folder contains the files for that particular branch.
If you changed the execution policy, you can reset it by closing PowerShell or by running:
Set-ExecutionPolicy -Scope Process -ExecutionPolicy Restricted