2

I'm trying to use the command git init. However, I'm getting this error:

git : The term 'git' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ git init
+ ~~~
    + CategoryInfo          : ObjectNotFound: (git:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

Not sure if it's related to the difference in the locations of the project folder and the git executable but here's the info:

The location of the folder in which I'm working is:

S:\Everything\Coding\modern_portofolio

The location of the git installation is:

S:\Everything\Software\Git
Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • you have to put `git` in the path. It is proposed when installing. Did you refused to do it? or maybe didn't restarted your computer so that takes effect... – Philippe Oct 02 '20 at 11:41
  • @Philippe indeed, a restart worked like a charm. Thank you – Sebastian Hotoi Oct 04 '20 at 07:57
  • Does this answer your question? ['git' is not recognized as the name of a cmdlet](https://stackoverflow.com/questions/63686488/git-is-not-recognized-as-the-name-of-a-cmdlet) – Gino Mempin Apr 06 '21 at 00:24
  • What does the command `where git` (Windows) or `which git` (Bash) tell you? – Daniel Mann Sep 01 '22 at 22:12

2 Answers2

1

Try and launch your VSCode from a CMD session where your PATH was correctly setup.

set GH=C:\path\to\git
set PATH=%GH%\bin;%GH%\usr\bin;%GH%\mingw64\bin;%PATH%

Then the git command should be recognized from within VSCode console, be it a PowerShell one or any other.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thank you for the help. Before doing this, I've also followed Phillippe's above advice and gave a restart to the PC which solved the issue. I might have not restarted when I installed it. – Sebastian Hotoi Oct 04 '20 at 07:58
0

In case it helps someone else who gets sent here via google: I was having this issue, but the standard "reinstall git" and "fix your PATH" advice wasn't working for me. My problem turned out to be unrelated to git specifically, but my symptoms were as follows:

  1. git in Powershell: The term 'git' is not recognized as the name of a cmdlet...
  2. .\git.exe in Powershell: command prompt opens and immediately closes, no error or response at all in Powershell
  3. git in Command Prompt: everything works normally

If you don't have those symptoms, then this probably isn't going to help you, but for those who do...

Open up your Environment Variables (Start -> Edit the System Environment Variables -> Environment Variables...), and make sure that you have one named PATHEXT in the "System variables" group box. The default values for Windows 10 are as follows:

.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

Somehow mine had gotten cleared out. Setting PATHEXT to that and then restarting Powershell/VSCode solved the issue.

zfrank
  • 388
  • 2
  • 6