PowerShell ISE throws an error on git checkout PowerShell ISE throws an error on git checkout powershell powershell

PowerShell ISE throws an error on git checkout


There are few ways you can avoid these errors, none of them looks or feels 'natural'.First one uses error stream redirection and some logic around errors:

$out = git ? 2>&1if ($?) {    $out} else {    $out.Exception}

Second depends on the ErrorAction, that is available only for PowerShell constructs, so we need to build one first:

& {    [CmdletBinding()]    param()    git ?} -ErrorAction SilentlyContinue -ErrorVariable failif ($fail) {    $fail.Exception}

In my ISEGit module I use latter to avoid error records 'leaking' to end user in uncontrolled manner.

Finally you can 'fix it' (well, sort off...) by making sure you can a string in the end:

"$(git ? 2>&1 )"

Or something I would vote against as it will leave you unaware of any actual errors, setting global $ErrorActionPreference to SilentlyContinue - though this is not different from redirecting error stream to $null.


As specified here, adding -q after the command for quietness won't show these kind of errors.


It looks like you can now redirect stderr to stdout throughout your powershell script by simply setting an environment variable:

$env:GIT_REDIRECT_STDERR = '2>&1'