Skip to content

Instantly share code, notes, and snippets.

@johnallers
Created June 8, 2020 21:07
Show Gist options
  • Save johnallers/ab65018431892100fc12b99563d72b1b to your computer and use it in GitHub Desktop.
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
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