Skip to content

Instantly share code, notes, and snippets.

@dennisroche
Last active May 2, 2016 10:15
Show Gist options
  • Save dennisroche/967b9835fcaed4bcbeba to your computer and use it in GitHub Desktop.
Save dennisroche/967b9835fcaed4bcbeba to your computer and use it in GitHub Desktop.
PoshGit Helpers
# clean remote and local branches
function Git-Prune {
git fetch origin
Write-Host "Pruning remote branches" -ForegroundColor Magenta
git remote prune origin
Write-Host "Pruning local branches that have been merged to master" -ForegroundColor Magenta
git branch --merged $Commit |
? { $_ -notmatch '(^\*)|(^. master$)' } |
% { git branch $(if($Force) { '-D' } else { "-d" }) $_.Substring(2) }
}
# posh-git, prune local branches that have been merged into master
function Git-DeleteMergedBranches ($Commit = 'HEAD', [switch]$Force) {
git branch --merged $Commit |
? { $_ -notmatch '(^\*)|(^. master$)' } |
% { git branch $(if($Force) { '-D' } else { "-d" }) $_.Substring(2) }
}
# delete merge artifacts from disk
function Git-CleanMergeArtifacts {
git status -su | select-string -pattern "\.orig$" | ForEach-Object {
$_.ToString().TrimStart("?? ")
} | ForEach-Object {
rm $_ -Confirm
}
}
function Git-UpdateMasterWithOrigin {
try {
Write-Host "Finding all Git repositories..." -ForegroundColor Green -NoNewLine
$allRepos = Get-ChildItem -Directory -Force -Recurse -Hidden -Filter '.git' -Name | %{ $_ -replace '\\.git' }
Write-Host " Found $($allRepos.Count)." -ForegroundColor Green
$allRepos | ForEach-Object {
$repo = Join-Path . $_ -Resolve
Write-Host
Write-Host "Updating $repo" -ForegroundColor Magenta
Push-Location $repo
& git fetch origin --prune
& git checkout master
& git merge origin/master --ff-only
Pop-Location
}
} finally {
Pop-Location
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment