Created
June 8, 2020 21:07
-
-
Save johnallers/ab65018431892100fc12b99563d72b1b to your computer and use it in GitHub Desktop.
PowerShell function to fetch a repo and reset the current branch to the latest
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 Reset-Git { | |
$target = '' | |
if ($args){ | |
$target = "origin/$args" | |
} | |
else { | |
$current = (&git rev-parse --abbrev-ref HEAD) | |
$target = "origin/$current" | |
} | |
Write-Host "Performing fetch and hard reset to $target..." | |
$headBefore = (&git rev-parse HEAD) | |
& git fetch -p;git reset --hard $target | |
$headAfter = (&git rev-parse HEAD) | |
Write-Host "...done." | |
Write-Host | |
Write-Host "HEAD before: $headBefore" | |
Write-Host "HEAD after: $headAfter" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment