Charles Clayton
Charles Clayton

Reputation: 17976

Trying to commit to GitHub using powershell results in error "fatal: unable to access 'Microsoft.PowerShell.Core\FileSystem"

I want to run a powershell script to push to git automatically every so often.

I have GitHub installed for windows. If I run "Git Shell", a powershell shell opens but it has the git function installed and starts in C:\Users\crclayton\Desktop\GitHub> not in H:\>

If I try to use git in a normal PowerShell, it tells me git isn't recognized as a function. However, if I load the script C:\Users\crclayton\AppData\Local\GitHub\shell.ps1 in the normal powershell, I can use git, but when I navigate to the folder and try to add or commit or push, I get the error:

git.exe : fatal: unable to access

'Microsoft.PowerShell.Core\FileSystem::\mypath../.config/git/config': Invalid argument At

C:\Users\crclayton\Desktop\autogit.ps1:7 char:4

  • git <<<< add *

  • CategoryInfo : NotSpecified: (fatal: unable t...nvalid argument: String) [], RemoteException

  • FullyQualifiedErrorId : NativeCommandError

This is my code:

#(Resolve-Path "$env:LOCALAPPDATA\GitHub\shell.ps1") # tried this, doesn't work
C:\Users\crclayton\AppData\Local\GitHub\shell.ps1

$msg = Read-Host "Enter commit msg"

cd "C:\Users\crclayton\project\"
git add *
git commit -a -m $msg
git push origin master

Can anyone see what's wrong or suggest an alternative? Thanks in advance.

Upvotes: 3

Views: 4529

Answers (2)

Volodymyr Daiev
Volodymyr Daiev

Reputation: 66

If you want to use git commands inside a powershell script make sure you have a record in the environment variable 'Path' with the actual path to the git. In my case it looks as shown on the attached picture!:

Path environment variable

Anyway, this setting was automatically added when I installed Git Extensions. If you don't use extensions just add this line to the 'Path' variable eather manually or from powershell script.

Hope this will help

Upvotes: 2

talves
talves

Reputation: 14353

Github for windows uses posh-git so you may want to confirm that you are following the manual install to be used by powershell.

Verify execution of scripts is allowed with Get-ExecutionPolicy (should be RemoteSigned or Unrestricted). If scripts are not enabled, run PowerShell as Administrator and call Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm.

Upvotes: 1

Related Questions