Last active
June 7, 2025 14:19
-
-
Save GustavoAmerico/dd2da52b6a8b2da5db3df45bb0439d05 to your computer and use it in GitHub Desktop.
Essa função é responsável por centralizar alguns comandos verbosos do git
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
#Author: Gustavo Américo | |
#Repository: https://gist.github.com/GustavoAmerico | |
function Git-Update-All-BranchsFromBase { | |
#Esse script é responsável por executar um merge automático de uma branch base para todas as outras branchs. Em caso de conflitos o script faz rollback e pula a branch conflitante | |
param([Parameter(Mandatory = $true)][String]$branchNamePattern, $remoteName = 'origin', $branchBase = 'master') | |
$branchsToUpdate = (git branch --all | % { $_.ToString().Replace("remotes/$remoteName/", '').Trim() } | Select-String -Pattern $branchNamePattern); | |
$branchsToUpdate | % { | |
git checkout $_; | |
git merge "$remoteName/$branchBase" --no-ff --no-edit; | |
if (-not $?) { | |
git merge --abort; | |
git reset --hard | |
}else { | |
git push | |
} | |
} | |
} | |
function Git-Remove-Merged-Branchs { | |
#ATENÇÃO: Esse comando não verifica se as alterações forma mescladas com a branch principal!! O branch vai ser apagado | |
#Faça checkout na branch que você deseja utilizar como base | |
param([Parameter(Mandatory = $true)][String]$branchNamePattern, $remoteName = 'origin') | |
git pull --all; | |
git branch --all --merged | Select-String -Pattern $branchNamePattern | % { | |
$_.ToString().Replace("remotes/$remoteName/", '').Trim() | |
} | % { | |
try{ git push origin :$_; } | |
catch{ git branch -D $_; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment