Last active
March 1, 2018 16:35
-
-
Save mu88/1d7eec283e2140cf57ca1243c7d92480 to your computer and use it in GitHub Desktop.
Git - Set default branch
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
Clear-Host | |
$ErrorActionPreference = 'Stop' | |
$Git_Branch = 'develop' | |
$Git_Base_Directory = 'C:\Git' | |
# get all existing Git repositories => For this, L:\src get filtered for all folders ending on 'v' and a digit because only those folders are accesibble via Git-Server | |
$Git_Repos = Get-ChildItem $Git_Base_Directory | ?{ $_.PSIsContainer } | Where-Object {$_.Name -match '\w*v\d\b'} | Select-Object Name | |
ForEach($Git_Repo in $Git_Repos) | |
{ | |
$Git_Repo_Name = $Git_Repo.Name | |
$Git_Repo_Directory = Join-Path -Path $Git_Base_Directory -ChildPath $Git_Repo_Name | |
cd $Git_Repo_Directory | |
# get the repo's current default branch | |
$Git_Repo_CurrentDefaultBranch = git symbolic-ref HEAD | |
$Git_Repo_DefaultIsDevelopBranch = $FALSE | |
if ($Git_Repo_CurrentDefaultBranch -like "*$Git_Branch*") | |
{ | |
$Git_Repo_DefaultIsDevelopBranch = $TRUE | |
} | |
# if the default branch is already set to develop, it doesn't have to be set again | |
if ($Git_Repo_DefaultIsDevelopBranch) | |
{ | |
continue | |
} | |
"Git repo's '$Git_Repo_Name' default branch has to be set to $Git_Branch`-branch" | |
git symbolic-ref HEAD refs/heads/$Git_Branch | |
Start-Sleep 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment