Skip to content

Instantly share code, notes, and snippets.

@jonnypetraglia
Last active April 11, 2024 19:57
Show Gist options
  • Save jonnypetraglia/f305fe584a117020ff79c9d817389389 to your computer and use it in GitHub Desktop.
Save jonnypetraglia/f305fe584a117020ff79c9d817389389 to your computer and use it in GitHub Desktop.
Powershell Scripts
function ExitOnError{
if (-Not $?) { exit 0 }
}
function Jonny-MergeBranch($Target = 'environment/integrate', [Switch]$Push = $false){
$TargetWhatever = ($Target -split '/')[-1]
$CurrentBranch = (git branch --show-current)
$TicketNumber = ($CurrentBranch -split '/')[-1]
git fetch
ExitOnError
$MergeBranchName = "merge/$TargetWhatever/$TicketNumber"
echo $MergeBranchName
if($null -ne (git show-ref --heads "$MergeBranchName")){
echo 'Exists'
git checkout $MergeBranchName
ExitOnError
git merge --ff "origin/$MergeBranchName"
ExitOnError
}else{
echo 'Creating'
git checkout -b $MergeBranchName --no-track "origin/$Target"
ExitOnError
}
git merge $CurrentBranch
ExitOnError
if($Push){
git push -u origin $MergeBranchName
ExitOnError
}
git checkout $CurrentBranch
ExitOnError
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment