3

I'm trying to upload my React app to my GitHub repository, but Visual Studio Code won't recognize a Git command.

I have Git on the PC. The path to Git is correct, and I checked multiple times. I have installed GitHub Pages through the Visual Studio Code terminal. I have also added the required changes to file package.json. Now when I run git init in the Visual Studio Code terminal, it throws an error that "git" is not a recognized command. Why is that happening and how can I fix it?

This is the Git path in Visual Studio Code - "git.path": "C:/Program Files/Git/bin/git.exe". It is correct.

Git Enabled is checked as well.

File package.json edits under the first {} "homepage": "http://greardrear.github.io/messenger", is added and under scripts added "predeploy": "npm run build", "deploy": "gh-pages -d build", .

And when I try to do "git init" or "git remote add origin", I get this message in the Visual Studio Code terminal:

 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
+ ~~~
    + CategoryInfo          : ObjectNotFound: (git:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

How can I fix this?

PS. I have tried all of the "fixes" to this issue I could find. I have also tried changing the path to "git.path": "C:/Program Files/Git/git-bash.exe" which also didn't work.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Marko Stanojevic
  • 33
  • 1
  • 1
  • 7
  • Likely canonical (2015, 36 answers, and 221 votes): *[Visual Studio Code cannot detect installed Git](https://stackoverflow.com/q/29971624/)*. – Peter Mortensen Dec 17 '22 at 02:10

2 Answers2

4

From the comment of my previous answer, check first if simply restarting the PC would help.

PowerShell might need that to fully recognize the Git for Windows installation.

That or reinstall Git for Windows again.


Note that I do also mention in "Visual Studio Code cannot detect installed Git" the Visual Studio Code 1.50 (September 2020) new feature:

Support multiple values for the git.path setting

That can help when you are using Visual Studio Code with settings synchronized on multiple machines, with Git installed in different paths on said machines.

And don't forget "git.enabled": true.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Oh wow, apparently i was so cought up in the moment i didnt think of just restarting.... Thank you @VonC – Marko Stanojevic May 08 '21 at 15:10
  • 3
    No problem. 25 years in computer engineering, and "did you try to stop, restart it again?" is still as effective as ever ☺️ – VonC May 08 '21 at 15:21
  • When a Windows program is installed that changes the `PATH`, there is a message that the installer can send such that running applications pick up the new value. Either that is not being done, or the programs in question which are not picking up the changed `PATH` aren't handling it. – Kaz Dec 28 '22 at 20:30
  • E.g. under the NSIS installer system, the `EnvVarUpdate.nsh` script is used for updating environment variables. It sends a `WM_WININICHANGE` to the `HWND_BROADCAST` handle, with a particular parameter, and waits with a 50 second timeout. – Kaz Dec 28 '22 at 20:37
  • @Kaz Interesting, thank you for the feedback. Do you have a documentation link to illustrate that? Would that apply to the OP's question? – VonC Dec 28 '22 at 20:53
0

Firstly, download and install the latest Git implementation from the link below:

https://git-scm.com/download/win

Then you have to add environment variables. Go to System Environment Variables and add the following:

C:\Program Files\Git\bin

C:\Program Files\Git\cmd

Click OK and close your terminal. Now open the terminal again and check the command you're are looking for, i.e., git --version (it gives you the installed version).

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • Is it [actually called](https://stackoverflow.com/questions/9546324/adding-a-directory-to-the-path-environment-variable-in-windows/72341522#72341522) *"System Environment Variables"* or has this been copied from somewhere else? What version of Windows? – Peter Mortensen Dec 28 '22 at 20:34