7

I'm trying to clone a project of GitHub into Visual Studio, so I go to New Terminal and type:

git clone [CLONE WITH SSH LINK]

and it shows:

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.

However, I have already installed Git and Git is set to Enabled at Visual Studio settings.

Why does this error occur, and how can I fix it?

And how can I set/change the path of Git in Visual Studio...

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 2
    `git` is not in the search `PATH` of the environment that is trying to execute it (and no absolute path is not being used). – Ondrej K. Sep 01 '20 at 11:21
  • @OndrejK. Plz tell me how to set path –  Sep 01 '20 at 11:31
  • This is likely about [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code), not [Visual Studio](https://en.wikipedia.org/wiki/Visual_Studio). Nowadays, it is statistically always Visual Studio Code, never Visual Studio (thanks for nothing, Microsoft marketing). "New Terminal" is a menu command in Visual Studio Code (menu *Terminal* → *New Terminal*). There is also an entry in *Settings* in Visual Studio Code by the name *"Git. Enabled"* – Peter Mortensen Dec 17 '22 at 01:15
  • But this is very likely a duplicate. There are known problems getting Git to work together with Visual Studio Code (in its built-in terminal window - which may be different from a CMD, PowerShell or [Git Bash](https://superuser.com/questions/1053633/what-is-git-bash-for-windows-anyway) window). It could also depend on the version of Visual Studio Code. ***What is the canonical question?*** – Peter Mortensen Dec 17 '22 at 01:19
  • Candidates: *[Git commands in Visual Studio Code Terminal are not working, yet they work on the cmd prompt](https://stackoverflow.com/q/58189196/)*, *[Git is not recognized in Visual Studio Code](https://stackoverflow.com/q/69375464/)*, *[Git is not recognised in Visual Studio Code](https://stackoverflow.com/q/50639459)*, *[Visual Studio Code does not recognize Git](https://stackoverflow.com/q/47849984/)*, and *[Visual Studio Code cannot detect installed Git](https://stackoverflow.com/q/29971624/)*. – Peter Mortensen Dec 17 '22 at 01:55
  • The last one (2015, 36 answers, and 221 votes) may be the canonical. – Peter Mortensen Dec 17 '22 at 01:56
  • Likely canonical for non-program-specific (2010, 42 answers, and 600 votes): [Errror "'git' is not recognized as an internal or external command"](https://stackoverflow.com/questions/4492979/git-is-not-recognized-as-an-internal-or-external-command) – Peter Mortensen Dec 17 '22 at 02:02
  • Though "[cmdlet](https://en.wikipedia.org/wiki/PowerShell#Cmdlets)" in this question could suggest it is for Windows. – Peter Mortensen Dec 17 '22 at 02:03

3 Answers3

9

Reinstall Git and reopen the editor

I solved the same problem by reinstalling Git.

And refreshed npm.

Then I closed the editor and reopened it.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
SystemX
  • 481
  • 4
  • 10
  • What editor? [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code)? [Visual Studio](https://en.wikipedia.org/wiki/Visual_Studio)? – Peter Mortensen Dec 17 '22 at 01:23
4

The reason behind it is that you might have not added the Path environment variable. So here are the steps for that.

Go to Environment Variable. Click on to the Path variable, Edit and add it to the path given below:

C:\Program Files\Git\bin

C:\Program Files\Git\cmd

Click OK and close your terminal. Now open the terminal and check the command. You're looking for e.g. git --version. It gives you the version you have installed.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • On Windows, presumably? The question is probably about [Visual Studio Code](https://en.wikipedia.org/wiki/Visual_Studio_Code), not [Visual Studio](https://en.wikipedia.org/wiki/Visual_Studio). Though it could still be on Windows. – Peter Mortensen Dec 17 '22 at 01:24
  • It is odd that the installation hadn't added paths automatically, but adding manually worked. My prior git installations were adding paths automatically. – Tim Kochetkov Mar 29 '23 at 16:25
0

I just reopened Visual Studio right after installing Git and that solved the issue for me! Just make sure to make it default for Visual Studio and allow third party command prompt.

Leosanab
  • 1
  • 1