Skip to content

Instantly share code, notes, and snippets.

@zooba
Created February 27, 2020 20:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zooba/59011cbc25d80a006b7eacc554a08570 to your computer and use it in GitHub Desktop.
Save zooba/59011cbc25d80a006b7eacc554a08570 to your computer and use it in GitHub Desktop.
Git-Sync Powershell function
function Git-Sync {
git fetch --all --prune;
$alive = git for-each-ref refs/remotes --format '%(refname)';
$dead = git for-each-ref refs/heads --format '%(if)%(push)%(then)%(refname:short):%(push)%(end)' `
| ?{ ($_ -split ':')[1] -and -not (($_ -split ':')[1] -in $alive) } `
| %{ ($_ -split ':')[0] };
if ($dead) {
$current = git name-rev --name-only HEAD;
if ($current -in $dead) {
Write-Host "Branch '$current' about to be deleted."
$newb = Read-Host -Prompt "git checkout: [master] "
if ($newb) {
git checkout $newb;
} else {
git checkout master;
}
}
git branch -D $dead;
}
git pull;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment