Skip to content

Instantly share code, notes, and snippets.

@bradwilson
Created November 6, 2012 16:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradwilson/4025806 to your computer and use it in GitHub Desktop.
Save bradwilson/4025806 to your computer and use it in GitHub Desktop.
param(
[string]$server = "origin",
[string]$branch = "master"
)
$gitStatus = (Get-GitStatus)
if ($gitStatus -eq $null) {
write-error "Not in a Git repository."
} elseif ($gitStatus.HasUntracked -or $gitStatus.HasWorking -or $gitStatus.HasIndex) {
write-error "Can't switch to $branch when you have uncommited changes."
} else {
$oldBranch = $gitStatus.Branch
if ($branch -ne $oldBranch) { git checkout $branch }
git pull --rebase $server
git remote prune $server
if ($branch -ne $oldBranch) { git checkout $oldBranch }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment