ChatGPT解决这个技术问题 Extra ChatGPT

'git' is not recognized as an internal or external command

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?

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.
I installed Git and tried using Command prompt under actions in Team explorer/Changes.
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
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.
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.

M
MultiplyByZer0

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:

In the Start Menu or taskbar search, search for "environment variable". Select "Edit the system environment variables". Click the "Environment Variables" button at the bottom. Double-click the "Path" entry under "System variables". 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. Close and re-open your console.

Modifying PATH on Windows 7:

Right-click "Computer" on the Desktop or Start Menu. Select "Properties". On the very far left, click the "Advanced system settings" link. Click the "Environment Variables" button at the bottom. Double-click the "Path" entry under "System variables". 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. Close and re-open your console.

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

How to set the path and environment variables in Windows (Computer Hope)

How to edit your system PATH for easy command line access in Windows (How-To Geek)

How to set Path environment variables in Windows 10 (Addictive Tips)

What are PATH and other environment variables, and how can I set or use them? (Super User)


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
Or use GitShell, press Start and type "GitShell" to locate it. You do not have to worry about the Path stuff anymore.
put in bold the "Do not add a space between ; and last entry" part. Ate one hour of my time X(
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.
Is there a difference between cmd and bin?
E
ErikE

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


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.
Oops.. I wasted 20+ mins without realizing that I've to re-open my cmd prompt. Your answer worked for me!! Thanks.
This worked for me as well, because I was using Powershell inside VS Code. Re-opening the application did the trick. Thank you.
this resolved the issue for me on Win 10
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.
S
Skitty

Go to My Computer => Local Disk(C:) => Program Files(x86) => Git => cmd Right Click the git => Select Properties Under the location Copy the text eg - C:\Program Files (x86)\Git\cmd Come back to the Desktop Right-click My Computer Select property Open Advanced Click Environment Variables In the System variables Find the Variable call Path Click the variable Click the Edit Button Select the Variable value Text Box . Go to the edge of the text and put semicolon(;) Then Right-click and press Paste Press Ok


J
Justice O.

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

https://i.stack.imgur.com/6KElW.png


Full instructions on configuration of Git on Windows: phoenixnap.com/kb/how-to-install-git-windows
M
MultiplyByZer0

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.


C:\Users\yourname\AppData\Local\GitHub\PortableGit_8810fd5c2c79c73adcc73fd0825f3b32fdb816e7/cmd is what worked for me.
R
Robbie Wxyz

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

open command prompt < run --> cmd > Run below command. set PATH=C:\Program Files\Git\bin;%PATH% 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


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.
Thx! PS. If adding git/bin file does not work, try adding git/cmd to the path as well.
l
live-love

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.


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!!
J
Jeeves

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

Takes you directly to the Git Shell.


r
reZach

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:

Press Start. Search for "GitHub" (without quotes) 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

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.


C
CaptainGenesisX

If you're using Windows 10, do this:

Go to Start Start typing 'This PC' Right-click This PC, choose Properties On the left side of the window that pops up, click on Advanced System Settings Click on the Advanced tab Click on the Environmental Variables button at the bottom Down in the System Variables section, double-click Path Click the New button in the top right corner Add this path: C:\Program Files\Git\bin\ then click the enter key Add another path: C:\Program Files\Git\cmd 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.


D
Dharman

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.


T
ToDo

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.


u
user13592342

Search for GitHubDesktop\app-2.5.0\resources\app\git\cmd Open the File Copy File location. Search for environment. open edit system environment variable. open Environment Variables. on user variable double-click on Path. click on new past OK Open path on system variables. New, past the add \ (backslash), then OK 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.


D
Dharman

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.


T
Thamaraiselvam
;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


j
johnmanoahs

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.


I think the user was using just git, not the github app.
D
Devendra Singraul

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


G
Ghanendra

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.


N
Negin msr

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


P
Praneeth Pj

I fixed it by changing the Target framework into the .Net 6.0.

To do that, please follow this path.

Solution Explorer -> right click on project -> properties

And then try to change the framework.

https://i.stack.imgur.com/jkXEA.png


K
K PETER

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

right click on the .bat file, edit with notepad++. find path. 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!