Created
February 27, 2020 20:46
-
-
Save zooba/59011cbc25d80a006b7eacc554a08570 to your computer and use it in GitHub Desktop.
Git-Sync Powershell function
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
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