4

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?

5
  • What are you typing in PowerShell to run git? Commented Aug 10, 2017 at 9:18
  • 1
    just git or to get version git --version Commented Aug 10, 2017 at 9:19
  • What's the output of Get-Command git? It should point to git.exe if the path environment variable is properly set. Commented Aug 10, 2017 at 9:21
  • output of command CommandType Name Version Source ----------- ---- ------- ------ Application git 0.0.0.0 C:\WINDOWS\system32\git Commented Aug 10, 2017 at 9:25
  • 1
    Seems you have an erroneous file in your system directory named git. 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 named git. Commented Aug 10, 2017 at 9:35

2 Answers 2

9

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)
Sign up to request clarification or add additional context in comments.

2 Comments

I'm really sorry for this comma mess; would love if someone could fix it
Also (temporary fix): if you have Git in your 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.
4

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

1 Comment

This worked for me by making the change then just restarting Powershell not the whole computer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.