Error "'git' is not recognized as an internal or external command"
Asked Answered
D

27

661

I have an installation of Git for Windows, but when I try to use the git command in Command Prompt, I get the following error:

'git' is not recognized as an internal or external command,
operable program or batch file. 

How do I fix this problem?

Dextrad answered 20/12, 2010 at 19:13 Comment(7)
The content added by garbage collection in the edit on changing the path should be part of Abizem's answer, a new answer, or at least in the comments to Abizem's answer. It should not be part of the question.Glosseme
I installed Git and tried using Command prompt under actions in Team explorer/Changes.Graben
I had the same problem when I am trying to change the proxy settings to install some packages from github in R. Later only I have realized that I didnot install git itself. I was having github desktop. It didnt stike me. Anyway, anyone comes here, please check whether you have installed git or not firstPhototopography
Related post - Why was git installed in AppData instead of Program Files? - This can also be an issue even after successful installation of Git. Please ensure that you run git setup with a user account having administrative privileges.Hydraulics
CMD was opened during the installation of GIT – If you recently installed Git for Windows while a Command Prompt window was opened, the issue might be resolved as soon as you re-open Command Prompt.Poultryman
add C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\Common7\IDE\CommonExtensions\Microsoft\TeamFoundation\Team Explorer\Git\cmd to PATH if you are installed vs 2019.Ticktack
Here's a git not recognized error tutorial that helped me.Cuckoopint
B
876

You may not have set your PATH correctly to point at your Git installation.

You need to add the following paths to PATH:

  • C:\Program Files\Git\bin\
  • C:\Program Files\Git\cmd\

And check that these paths are correct. You may have Git installed on a different drive, or under Program Files (x86). Correct the paths if necessary.


Modifying PATH on Windows 10:

  1. In the Start Menu or taskbar search, search for "environment variable".
  2. Select "Edit the system environment variables".
  3. Click the "Environment Variables" button at the bottom.
  4. Double-click the "Path" entry under "System variables".
  5. With the "New" button in the PATH editor, add C:\Program Files\Git\bin\ and C:\Program Files\Git\cmd\ to the end of the list.
  6. Close and re-open your console.

Modifying PATH on Windows 7:

  1. Right-click "Computer" on the Desktop or Start Menu.
  2. Select "Properties".
  3. On the very far left, click the "Advanced system settings" link.
  4. Click the "Environment Variables" button at the bottom.
  5. Double-click the "Path" entry under "System variables".
  6. At the end of "Variable value", insert a ; if there is not already one, and then C:\Program Files\Git\bin\;C:\Program Files\Git\cmd\. Do not put a space between ; and the entry.
  7. Close and re-open your console.

If these instructions weren't helpful, feel free to look at some others:

Bemean answered 20/12, 2010 at 19:16 Comment(19)
If you dont know where is Git floder. In windows 7 the path could be: ;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmdLilienthal
Or use GitShell, press Start and type "GitShell" to locate it. You do not have to worry about the Path stuff anymore.Korea
put in bold the "Do not add a space between ; and last entry" part. Ate one hour of my time X(Meticulous
we know how to use Env. Variables we need to know which is the variable needed for that !!! I used Gitshell and got the same error.Sprayberry
You add the path of your git installation to your Path variable.Bemean
Which path should I add on PATH; <git_installation>\bin , <git_installation>\libexec\git-core or <git_installation>\cmd? Each of them contains git.exe.Geomancy
To find out where git is in your windows environment (or most apps for that matter), open powershell and do: {{{ where.exe git }}}Headwaiter
Is there a difference between cmd and bin?Bihar
Warn for jenkins slave users : "restarting the Jenkins service alone is not enough" via Leif Gruenwoldt & Joe Intrakamhang you will need to restart Windows to take effect.Acroterion
@Geomancy bin is the version to use according to this link. groups.google.com/forum/#!topic/msysgit/h7GcZXcYfmAGorget
Do not add a space between ; and last entry - This helped meCollywobbles
In my case i found path on C:\Users\pallav.bohara\AppData\Local\Programs\Git\binEmotion
If you wanna know the git path folder, open a command prompt in windows OS and type: where gitGlossitis
@Abizern: when calling git.exe using subprocess in Python (on windows 10), should we use the one from bin/ or the one from cmd/? (also see comment by @thomas)Treacherous
@Dennis As I'm not an active Windows user I don't know. It might be worth asking a separate question about this.Bemean
In case if you are still getting error after setting the PATH variables, just restart your machine and it will work.Easily
for me the insallation was in the C:\Users\<myuser>\AppData\Local\Programs\Git\bin...You can search your directory by doing "Open file location" for any of the git shortcuts. Basically you locate the git.exe and add that to your pathEmersed
worked for me only after restarting windows (even though restart is not supposed to be required)Duston
Even to this very day with Visual Studio 2019's latest update(yesterday - 13/10/2021) they like removing Git from the Environment variables' path. This is my go to comment for fixing this, so big props to you helping to fix Microsoft's regressions!Testes
J
232

If you opened the cmd prompt before installation of Git, close and reopen it.

Jacey answered 20/2, 2013 at 2:18 Comment(5)
For people wondering why this can solve the issue, Environment Variables are only read when an application (in this case cmd) is launched. Relaunching it would allow it to read again the Environment Variables and see the updated PATH.Hilda
Oops.. I wasted 20+ mins without realizing that I've to re-open my cmd prompt. Your answer worked for me!! Thanks.Galactometer
This worked for me as well, because I was using Powershell inside VS Code. Re-opening the application did the trick. Thank you.Ombudsman
this resolved the issue for me on Win 10Custombuilt
It's also worth noting that if using Windows Terminal in Windows 11, closing the tab and reopening doesn't reinitialize the environment. All tabs need to be closed and Windows Terminal needs to be completely restarted to do so.Lothario
L
64
  1. Go to My Computer → Local Disk(C:) → Program Files(x86) → Git → cmd
  2. Right-click the git → Select Properties
  3. Under the location, copy the text. For example, C:\Program Files (x86)\Git\cmd
  4. Come back to the Desktop
  5. Right-click My Computer
  6. Select property
  7. Open Advanced
  8. Click Environment Variables
  9. In the System variables, find the Variable call Path
  10. Click the variable
  11. Click the Edit button
  12. Select the Variable value text box.
  13. Go to the edge of the text and add semicolon(;)
  14. Then right-click and press Paste
  15. Press OK
Lewallen answered 2/3, 2015 at 14:41 Comment(0)
L
57

An easy route to avoid messing with PATH variables: reinstall Git and select "Use Git from the Windows Command Prompt". It'll take of the PATH variables for you as mentioned. See the screenshot:

Enter image description here

Localize answered 16/12, 2015 at 20:16 Comment(2)
Full instructions on configuration of Git on Windows: phoenixnap.com/kb/how-to-install-git-windowsCanner
Hmm, I'm pretty sure I selected that, but possible I didn't.Regress
I
46

If you are using GitHub for Windows (GitHub's old Git GUI that is no longer available for download, not the new Electron-based GitHub Desktop), you have an installation of Git under:

C:\Users\<YOUR USERNAME>\AppData\Local\GitHub\PortableGit_8810fd5c2c79c73adcc73fd0825f3b32fdb816e7\cmd

Expand this path, and add it to PATH.

Idioplasm answered 14/2, 2013 at 6:27 Comment(1)
C:\Users\yourname\AppData\Local\GitHub\PortableGit_8810fd5c2c79c73adcc73fd0825f3b32fdb816e7/cmd is what worked for me.Sonnnie
P
38

If you want to set up for a temporary purpose, just execute the below command.

  1. Open a command prompt: Runcmd

  2. Run the below command.

    set PATH=C:\Program Files\Git\bin;%PATH%

  3. Type git. It will work.

This is valid for current windows/cell only. If you will close command prompt, everything will get vanish.

For permanently changing the setting, set the GIT environment variable.

  1. Press Window + Pause

  2. Click on Advanced system settings.

  3. Click on Environment variable under the Advanced tab.

  4. Edit Path Variable.

  5. Add the below line in end of the statement.

    ;c:\Program Files\Git\bin;

  6. Press OK!!

  7. Open a new command prompt <Point 1>.

  8. Type git and press Enter

Pollitt answered 18/9, 2015 at 11:13 Comment(2)
Good alternate suggestion to put it on the path temporarily. I would also suggest that one could just specify the full path to git in this scenario as well.Delative
Thx! PS. If adding git/bin file does not work, try adding git/cmd to the path as well.Jeaninejeanlouis
Q
11

If you get this error, you might not have Git installed in your system.

Download it here:

Downloads

Install it.

If you have Windows, you will now see a C:\Program Files\Git folder.

Open a new Command Prompt window, and try running the Git command again.

Quicksand answered 6/10, 2020 at 19:25 Comment(1)
the funny thing is after checknig your answser & upvoting it, I started going bakc to Visual studio to apply a git command without actually downloading and installing git on my new machine.. because I am.. sleepy!!Stir
C
7

Use Start menu → All ProgramsGitGit Bash.

It takes you directly to the Git shell.

Cuddy answered 14/7, 2015 at 16:23 Comment(1)
Presuming Git Bash is installed. Is that always the case?Ita
C
6

Yo! I had lots of problems with this. It seems that GitHub brings its own console which you need to look for in your drive. I managed to finally run it by doing the following:

  1. Press Start.

  2. Search for "GitHub" (without quotes)

  3. Right click on "GitHub" and select "Open File Location"

    This shall open:

    C:\Users\UserName\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\GitHub, Inc
    

    Where username is your PC's username.

  4. Look for a program called "Git Shell". Double-click on it.

This will open a PowerShell command prompt. Then you can run your Git commands normally on it.

Copper answered 4/7, 2015 at 22:56 Comment(0)
M
5

If you're using Windows 10, do this:

  1. Go to the Start menu

  2. Start typing 'This PC'

  3. Right-click This PC, and choose Properties

  4. On the left side of the window that pops up, click on Advanced System Settings

  5. Click on the Advanced tab

  6. Click on the Environmental Variables button at the bottom

  7. Down in the System Variables section, double-click Path

  8. Click the New button in the top right corner

  9. Add the path *C:\Program Files\Git\bin*, and then click the Enter key

  10. Add another path: C:\Program Files\Git\cmd

  11. Close and reopen the console if it's already open.

I stepped you through the long way so you gain exposure to the different Windows/menus.

Monmouthshire answered 9/2, 2019 at 15:54 Comment(2)
Re "click the Enter key": Do you mean press the Enter key? Or click button "Enter" (or some other button, like "OK" or "Apply")?Ita
Peter, unfortunately I don't remember anymore but I believe I was referring to whatever the confirmation button was (i.e. OK, Apply, etc. as you suggested)Monmouthshire
H
4

That's because at the time of installation you have selected the default radio button to use "Git" with the "Git Bash" only. If you would have chosen "Git and command line tool" then this would not be an issue.

  • Solution #1: as you have already installed a Git tool, now navigate to the desired folder. Right-click, use "Git Bash here" to run the same command, and it will run properly.

  • Solution #2: try installing the Git-scm again and select the proper choice.

Hospodar answered 28/11, 2015 at 12:40 Comment(3)
Or in other words, uninstall and reinstall with checkbox "Git and command line tool" checked/enabled.Ita
What version? It seems to be inconsistent with this answer. Or is it another screen in the installation wizard?Ita
All the installation wizard screens are documented here (though that may be specific for a particular version).Ita
W
4
  1. Search for GitHubDesktop\app-2.5.0\resources\app\git\cmd
  2. Open the File
  3. Copy File location.
  4. Search for environment.
  5. open edit system environment variable.
  6. open Environment Variables.
  7. on user variable double-click on Path.
  8. click on new
  9. past
  10. OK
  11. Open path on system variables.
  12. New, past the add \ (backslash), then OK
  13. Search for GitHubDesktop\app-2.5.0\resources\app\git\usr\bin\ 14 Copy the Address again and repeat pasting from step 4 to 12.
Weka answered 21/5, 2020 at 21:23 Comment(1)
Re "Search for GitHubDesktop\app-2.5.0\resources\app\git\cmd": Where? On the Internet? On GitHub? In the local file system?Ita
H
4

I've faced the issue, and it got solved after installing Git.

Download it from the Downloads page.

Handyman answered 24/8, 2022 at 13:12 Comment(1)
FWIW -- There are different variations supported in the docs github.com/git-guides/install-git#install-git-on-windows ----- gitforwindows.org is another option.Croissant
M
4

I have been suffering from this issues by using vscode. I just edit environment variable PATH on windows 10 as follows:

C:\Program Files\Git\bin

and reopen my terminal. It's working fine.

Montford answered 23/3, 2023 at 16:39 Comment(0)
N
3

I just wanted to add to Abizern's answer.

If anyone is using a non-administrator account, you can create a "local" variable instead of a "system" variable which allows access to standard/limited accounts.

When in the "Environmental Variables" window:

  1. Select the "New..." button within the "User variables for ..." section.

  2. Set the "Variable name:" as "path" and "Variable value:" as "[your-git-path]" (usually found at C:\Program Files (x86)\Git\bin).

  3. Then click OK.

Nankeen answered 3/8, 2017 at 10:7 Comment(0)
T
2

This helps for me:

I set

C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd

in path for environment variables.

Trickster answered 6/9, 2018 at 15:42 Comment(2)
Re "I set": Don't you mean "I add"? In that case, append or prepend?Ita
More detailed instructions.Ita
T
2

Just check whether BitLocker has been enabled! I faced a similar issue where my Git in cmd was working fine. But after a quick restart, it didn't work, and I got the error as mentioned above.

So I had to unlock the BitLocker since I have installed Git in the hard disk drive volume (:E) which was encrypted by BitLocker.

Terrel answered 28/9, 2020 at 6:5 Comment(0)
F
2

This is fixed by re-installing Git for me. If still does not work, you may try this -

You need to add the following paths to PATH:

  • C:\Program Files\Git\bin\
  • C:\Program Files\Git\cmd\

And check that these paths are correct. You may have Git installed on a different drive, or under Program Files (x86). Correct the paths if necessary.

Modifying PATH on Windows 10:

  1. In the Start Menu or taskbar search, search for "environment variable".
  2. Select "Edit the system environment variables".
  3. Click the "Environment Variables" button at the bottom.
  4. Double-click the "Path" entry under "System variables".
  5. With the "New" button in the PATH editor, add C:\Program Files\Git\bin\ and C:\Program Files\Git\cmd\ to the end of the list.
  6. Close and re-open your console.
Finsteraarhorn answered 6/4, 2023 at 6:45 Comment(0)
B
2

There can be multiple reasons for the appearing error message.

In my case I tried to set the Git Path and still could not resolve this. The command prompt might need to be restarted to reflect the Git Path changes.

Here is link suggesting the similar thing. 3 ways to resolve the error - "'git' is not recognized as the name of a cmdlet"

Brattishing answered 25/9, 2023 at 20:21 Comment(0)
B
1

For future people, if you have this problem in VSCode (not cmd).

If your cmd and powershell recognize git, but VS Code does not, restart your pc and try it. This has worked for me multiple times.

Check if it is recognized with --git version

If not then follow the other comments. (This is first thing that pops up so I hope this comment helps other people with VSCode problems).

Brout answered 5/1 at 21:2 Comment(0)
B
0

Add this path in environment variables:

;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd

Note: the path may differ, but you should add both bin and cmd.

Brahms answered 16/4, 2016 at 11:56 Comment(3)
Re "Add this path in environment variables": That is too terse. Perhaps add a reference to instructions? There are probably hundreds on Stack Overflow. Though the canonical one would be preferred (may not be easy to find).Ita
There are some attempts in some of the answers here.Ita
One of the better attempts is this answer (but without any screenshots).Ita
C
0

After installation, open the GitHub application and in the top right corner you'd notice a settings icon. Select Options from the dropdown and choose "Default Shell" as Cmd.

Now try typing 'git shell' in the search (Windows key and type) and choose Git Shell. It should open up in CMD and Git should now be recognized.

Cheesecloth answered 16/6, 2016 at 13:15 Comment(1)
I think the user was using just git, not the github app.Baskin
D
0
  • Make sure correct the Git path is added to the Path variable in your Environment Variables. E.g., C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd. It can be different for your case, depending on where your Git gets installed.
  • If it doesn’t work, try restarting the command prompt, so that it reads the updated environment variables.
  • If it still doesn’t work, try restarting your machine to force the command prompt to read the updated environment variables.
Diesis answered 3/12, 2019 at 9:50 Comment(1)
More detailed instructions.Ita
E
0

I had this problem. When you install Git, you have to choose the right path. I mean, it should be the same path that you write git(code) in Git Bash

For example, if your path is C:\Users\username, you must install the Git in the same path (C:\Users\username). These two paths should not be different.

Eddo answered 17/5, 2020 at 18:6 Comment(0)
W
0

Just try restarting your machine if you have just installed Git. Worked for me

Woodwind answered 11/12, 2023 at 19:1 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.Chlorophyll
O
0

Based on my experience, if you encounter the error "'git' is not recognized as an internal or external command" or a similar issue with other commands while using the Windows Shell prompt, but these commands work correctly in the Command Prompt (cmd), even after ensuring that environment variables are appropriately configured and the Windows PowerShell is run as an administrator, you should verify the setting of the PATHEXT variable in the environment.

Ensure that the PATHEXT variable is correctly configured with the following file extensions: .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.WS;.MSC. This variable plays a crucial role in recognizing and executing commands.

enter image description here

Obscure answered 26/1 at 12:47 Comment(0)
N
-2

Windows 7 32 - bit

I am using Git for my Ruby on Rails application. First time so...

I created a .bat file for loading my Ruby on Rails applications with the paths manually typed using the tutorial How to install Ruby on Rails on Windows 7 - Part 1, Initial setup. If you are new to Ruby on Rails, you might want to check it out as I followed all steps and it works flawlessly after a few trials and errors.

(The .bat file is editable using Notepad++, hence there isn't any need for the long process. Whenever you need to edit a path, you can follow these simple process after creating a .bat file, following the tutorials on the link above "file is called row.bat".)

  1. Right-click on the .bat file,
  2. Edit with Notepad++.
  3. Find the path.
  4. Insert the path below the last path you inputted.

During the tutorials I don't remember anything was said in regards to using the Git command so when starting a new project, I had this same problem after installing Git.

The main issue I had was locating the folder with the bin/git.exe executable (git.exe did not show up in search using the Start menu's "search programs and files"). Note: I now understood that the location might vary drastically—see below.

To locate the bin/git.exe file I followed these steps:

  1. Left-click the Start menu and locate → All programs → *GitHub inc.
  2. Right-click Git shell and select open file location
  3. Click through the folders in the file location for the folder "bin"

I had four folders named:

  1. IgnoreTemplates_fdbf2020839cde135ff9dbed7d503f8e03fa3ab4
  2. lfs-x86_0.5.1
  3. PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad ("bin/exe, found here <<-")
  4. PoshGit_869d4c5159797755bc04749db47b166136e59132

Copy the full link by clicking on the Windows Explorer's URL (mine was "C:\Users\username\AppData\Local\GitHub\PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad\bin"). Open the .bat file in Notepad++ and paste using the instructions on how to add a path to your .bat file from the tutorials above. Problem is solved!

Nomenclator answered 7/6, 2015 at 23:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.