Created
October 28, 2025 02:15
-
-
Save WiiAhmad/0e00f67584004e00320903ef9fe9598c to your computer and use it in GitHub Desktop.
This script for git checkout all branch in remote, simple to use (run only with powershell)
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
| # ==================================================================== | |
| # Git Branch Checkout Script | |
| # ==================================================================== | |
| # | |
| # SETUP INSTRUCTIONS: | |
| # 1. Copy this entire script into a new file | |
| # 2. Save it as "git-checkout-all.ps1" (or any name you prefer) | |
| # 3. Place the file in a folder that contains a Git repository | |
| # | |
| # USAGE INSTRUCTIONS: | |
| # 1. Open PowerShell in the folder where you saved this file | |
| # 2. Load the functions by running: | |
| # . .\git-checkout-all.ps1 | |
| # | |
| # 3. Use the functions: | |
| # - To list all remote branches: | |
| # git-GetAllRemoteBranches | |
| # | |
| # - To checkout all remote branches locally: | |
| # git-CheckoutAllBranches | |
| # | |
| # EXAMPLE: | |
| # PS C:\MyProject> . .\git-checkout-all.ps1 | |
| # PS C:\MyProject> git-CheckoutAllBranches | |
| # | |
| # NOTE: Make sure you have committed or stashed any local changes | |
| # before running git-CheckoutAllBranches | |
| # ==================================================================== | |
| Write-Host "" | |
| Write-Host " Run with '. .\[Filename You save].ps1' " | |
| Write-Host " Then run only commands" | |
| Write-Host " - git-GetAllRemoteBranches : List all remote branches" | |
| Write-Host " - git-CheckoutAllBranches : Checkout all remote branches locally" | |
| Write-Host "" | |
| Function git-GetAllRemoteBranches { | |
| git branch -r | ForEach-Object { | |
| if ($_ -match "origin/(?'name'\S+)") { | |
| $matches['name'] | |
| } | |
| } | |
| } | |
| Function git-CheckoutAllBranches { | |
| git-GetAllRemoteBranches | ForEach-Object { | |
| git checkout $_ | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment