LowCool
LowCool

Reputation: 1411

git not running in powershell

I was facing issue with git in powershell so I uninstalled it and reinstall using this official post after installing when I open through shortcut as mentioned in post it worked. but if I open normal powershell I ran git command it is considering git as a file and asking me how do you want to open it? I am not understanding what happened there?

Upvotes: 4

Views: 19355

Answers (2)

Clijsters
Clijsters

Reputation: 4256

As you told us in the comments, Get-Command git returns:

CommandType Name Version Source
----------- ---- ------- ------
Application git  0.0.0.0 C:\WINDOWS\system32\git

Which shows, that your system32 folder contains a file named git (without extensions). As system32 is part of your %PATH%, typing git in your PowerShell, points to %WINDIR%\system32\git, and because it has no extension, Windows does not know, how to deal with it and asks you.

Why does this happen?

Usually this happens when one wants to pipe output from one command to another by using the wrong pipe operator in cmd, e.g. someCommand > git

To fix this, just remove git from system32 and ensure that your %PATH% ($env:Path in PowerShell) variable points to your git installation directory.

If not, add your git installation to %PATH%

  • either temporary by typing $env:Path += ";C:\path\to\git",
  • or permament
    • using System settings (like already described in other answer)
    • Using PowerShell:
      [Environment]::SetEnvironmentVariable("Path", $env:Path + ";C:\path\to\git", [EnvironmentVariableTarget]::Machine) (Machine can be replaced with User)

Upvotes: 8

ntshetty
ntshetty

Reputation: 1305

You need to set the git installation path to System environment variable PATH as follow pres windows home button then type advanced system settings

Environment Variable-->System variables-->path-->edit

add the the git installation path like this

;\git\path\bin

Then reboot your system, then try in powershell it should work

Upvotes: 4

Related Questions