553

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?

MultiplyByZer0
  • 5,209
  • 3
  • 29
  • 46
Jason Kim
  • 16,548
  • 13
  • 65
  • 102
  • 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. – gotgenes Dec 20 '10 at 20:29
  • 2
    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 first – David May 07 '18 at 04:57
  • 2
    Related post - [Why was git installed in AppData instead of Program Files?](https://stackoverflow.com/q/32297340/465053) - 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. – RBT Jul 09 '18 at 10:17
  • 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. – s.dragos Dec 25 '20 at 16:27
  • I installed Git and tried using Command prompt under actions in Team explorer/Changes. – Kurkula Feb 04 '16 at 19:49
  • 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. – Guido Mocha May 16 '21 at 08:51

20 Answers20

747

Have you correctly set your PATH 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:

MultiplyByZer0
  • 5,209
  • 3
  • 29
  • 46
Abizern
  • 138,728
  • 38
  • 201
  • 254
  • 104
    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\cmd – Jorge Nunez Newton Dec 16 '12 at 16:54
  • 12
    Or use GitShell, press Start and type "GitShell" to locate it. You do not have to worry about the Path stuff anymore. – Minh Triet May 08 '13 at 02:04
  • 6
    put in bold the "Do not add a space between ; and last entry" part. Ate one hour of my time X( – Nicu Surdu Oct 18 '13 at 11:01
  • 1
    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. – Konstantinos Korovesis Nov 04 '13 at 15:52
  • You add the path of your git installation to your `Path` variable. – Abizern Nov 04 '13 at 16:07
  • 6
    Which path should I add on **PATH**; `\bin` , `\libexec\git-core` or `\cmd`? Each of them contains `git.exe`. – IronBlossom May 29 '14 at 11:38
  • To find out where git is in your windows environment (or most apps for that matter), open powershell and do: {{{ where.exe git }}} – Jesse Nov 20 '14 at 16:48
  • 3
    Is there a difference between `cmd` and `bin`? – Thomas Sep 15 '15 at 15:21
  • Warn for **jenkins slave** users : "restarting the Jenkins service alone is not enough" [via Leif Gruenwoldt & Joe Intrakamhang](http://stackoverflow.com/questions/15231613/jenkins-git-release-failure) you will need to restart Windows to take effect. – boly38 Feb 02 '16 at 10:55
  • @IronBlossom bin is the version to use according to this link. https://groups.google.com/forum/#!topic/msysgit/h7GcZXcYfmA – AXMIM Feb 18 '16 at 14:45
  • **Do not add a space between ; and last entry** - This helped me – Chandra Shekhar Sep 12 '17 at 09:49
  • In my case i found path on C:\Users\pallav.bohara\AppData\Local\Programs\Git\bin – pallav bohara May 07 '18 at 14:54
  • If you wanna know the git path folder, open a command prompt in windows OS and type: where git – johnander11 Aug 20 '18 at 15:47
  • @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) – djvg Dec 12 '18 at 07:40
  • @Dennis As I'm not an active Windows user I don't know. It might be worth asking a separate question about this. – Abizern Dec 13 '18 at 09:12
  • 1
    In case if you are still getting error after setting the PATH variables, just restart your machine and it will work. – Janusz01 Apr 20 '19 at 05:26
  • for me the insallation was in the C:\Users\\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 path – ambassallo Nov 18 '20 at 12:21
  • worked for me only after restarting windows (even though restart is not supposed to be required) – Neil Jun 02 '21 at 01:07
  • 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! – Lee Oct 14 '21 at 08:45
192

Did you open the cmd prompt before installation of git? If so, close and reopen it.

ErikE
  • 46,564
  • 22
  • 147
  • 188
GP2
  • 2,106
  • 1
  • 13
  • 5
  • 17
    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`. – emartel Jul 03 '13 at 00:58
  • 6
    Oops.. I wasted 20+ mins without realizing that I've to re-open my cmd prompt. Your answer worked for me!! Thanks. – pavanw3b Mar 15 '15 at 13:15
  • 2
    This worked for me as well, because I was using `Powershell` inside VS Code. Re-opening the application did the trick. Thank you. – Surjith S M Sep 17 '18 at 12:17
  • this resolved the issue for me on Win 10 – gdogra Jan 30 '22 at 15:42
  • 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. – owacoder Mar 14 '22 at 15:28
56
  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 eg - 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 put semicolon(;)
  14. Then Right-click and press Paste
  15. Press Ok
Skitty
  • 1,609
  • 18
  • 20
48

Easy route to avoid messing with PATH variables: re-install git and select "Use Git from the Windows Command Prompt". It'll take of the PATH variables for you as mentioned. see screenshot

enter image description here

Justice O.
  • 1,173
  • 10
  • 19
45

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.

MultiplyByZer0
  • 5,209
  • 3
  • 29
  • 46
surinder singh
  • 1,369
  • 12
  • 12
  • 2
    C:\Users\yourname\AppData\Local\GitHub\PortableGit_8810fd5c2c79c73adcc73fd0825f3b32fdb816e7/cmd is what worked for me. – The_Martian Jan 06 '16 at 05:20
35

If you want to setup for temporary purpose, just execute below command.

  1. open command prompt < run --> cmd >
  2. Run below command.
    set PATH=C:\Program Files\Git\bin;%PATH%
  3. Type git, it will work.

This is valid for current window/cell only, if you will close command prompt, everything will get vanish. For permanently setting, set GIT in environment variable.

a. press Window+Pause
b. click on Advance system setting.

c. Click on Environment variable under Advance Tab.

d. Edit Path Variable.

e. Add below line in end of statement.
;c:\Program Files\Git\bin;

f. Press OK!!
g. Open new command prompt .
h. Type git and press Enter

Thanks

Robbie Wxyz
  • 7,326
  • 2
  • 29
  • 45
  • 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. – BuvinJ Oct 13 '15 at 17:23
  • Thx! PS. If adding `git/bin` file does not work, try adding `git/cmd` to the path as well. – Chris Tang Mar 03 '21 at 10:45
8

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

Download it here:

https://git-scm.com/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.

live-love
  • 41,600
  • 19
  • 198
  • 177
  • 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!!_ – Irf Jan 29 '21 at 06:44
5

Start->All Programs->Git->Git Bash

Takes you directly to the Git Shell.

Jeeves
  • 400
  • 1
  • 5
  • 23
4

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

  1. 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.

reZach
  • 7,573
  • 10
  • 48
  • 90
Jose A
  • 8,809
  • 9
  • 64
  • 92
3

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" than this would not be an issue.

  • Solution#1: as you have already installed Git tool, now navigate to the desired folder and then right click and use "Git bash here" to run your same command and it will run properly.
  • Solution#2: try installing again the Git-scm and select the proper choice.
Dharman
  • 26,923
  • 21
  • 73
  • 125
Dynamic Remo
  • 393
  • 6
  • 18
3

If you're using Windows 10, do this:

  1. Go to Start

  2. Start typing 'This PC'

  3. Right-click This PC, 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 this path: C:\Program Files\Git\bin\ then click the enter key

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

  11. Close & re-open the console if it's already open.

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

CaptainGenesisX
  • 170
  • 2
  • 9
2

Just wanted to add to Abizern 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 on the "Environmental Variables" window:

1) Select "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.

ToDo
  • 702
  • 2
  • 17
  • 29
2
  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.
1

Just check whether the Bit Locker has enabled!. I faced a similar issue where my GIT in the 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 Bit locker since I have installed GIT in the Hard drive volume (:E) which was encrypted by Bit Locker.

Dharman
  • 26,923
  • 21
  • 73
  • 125
Rahal Kanishka
  • 710
  • 11
  • 26
0
;C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd

add above path in environment variables

note: path may differ but you should add both bin and cmd

Thamaraiselvam
  • 6,739
  • 8
  • 45
  • 68
0

After installation, open the GitHub app and on the top right corner you'd notice a setting 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.

johnmanoahs
  • 73
  • 1
  • 1
  • 7
0

This helps for me : I set C:\Program Files (x86)\Git\bin;C:\Program Files (x86)\Git\cmd in path for environment variable.

0
  • Make sure correct git path is added to 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 doesnt work, try restarting the command prompt so that it reads the updated Environment Variables.
  • If it still doesnt work, try restarting your machine to force command prompt to read the updated Environment variables.
Ghanendra
  • 253
  • 1
  • 10
0

I had this problem,when you install the git,you have to choose the right path,i mean,it should be the same path that you write git(code)in the Git Bash...for example,if your path is c:\Users\username , you must install the git in same path(c:\Users\username)..these 2 paths should not be different

Negin msr
  • 113
  • 9
-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 RoR applications with the paths manually typed using this tutorial at "http://www.youtube.com/watch?v=-eFwV8lRu1w" 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 no 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 path.
  4. insert path below the last path you inputted.

    )
    During the tutorials I don't remember anything 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 (git.exe did not show up in search using 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 i followed this steps

1 left click start menu and locate ->> all programs ->> GitHub inc. 2 right click git shell and select open file location 3 click through folders in the file location for the folder "bin"

(I had 4 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 explorers url (mine was "C:\Users\username\AppData\Local\GitHub\PortableGit_c2ba306e536fdf878271f7fe636a147ff37326ad\bin") open .bat file in notepad++ and paste using instructions on how to add a path to your .bat file from tutorials above. Problem solved!

K PETER
  • 1
  • 1