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?
2 Answers
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)(Machinecan be replaced withUser)
2 Comments
system32 (and don't want to remove it) and installed Git via the installer, you might need to move C:\Program Files\Git\cmd before system32 in your path.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
gitor to get versiongit --versionGet-Command git? It should point to git.exe if the path environment variable is properly set.CommandType Name Version Source ----------- ---- ------- ------ Application git 0.0.0.0 C:\WINDOWS\system32\gitgit. Can't say it is safe to delete but you should investigate what it contains and then decide. Normal git installation doesn't put this file there so this is something else that just happens to be namedgit.