What do you do if git is not recognized as an internal or external command operable program or batch file?

Today in this article, we will cover below aspects,

Issue Description

git command line/CLI command gives below error,

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

This issue I found to be due to not setting up the proper environment variable on a machine where you already have installed the GIT component.

You might get the GIT component installed on your computer either using an external download or using IDE tools with Visual studio or VS code or other IDE.

Please note that this behavior could occur differently if you are using other vendors services leveraging GIT exe (which is an open-source utility) like GitHub lab or BitBucket while installing such services are you were your desktop applications.

Resolution

On a Windows machine, you need to set up a GIT-related environment variable.

Please follow below high-level steps required for you to fix the issue.

  • Install GIT CLI utility, if not done so already .
  • Check the file path for GIT installtion

Usually, GIT exe will be available in the below location,

C:\Program Files\Git\bin

Or

C:\Program Files\Git\cmd
What do you do if git is not recognized as an internal or external command operable program or batch file?
  • Update System environment variable for any of the above paths,
What do you do if git is not recognized as an internal or external command operable program or batch file?

Note: To make the variable effective, Please close any existing CMD or Bash shell window.

Alternatively,

If you are using GitHub tools like desktop or services then you may find the GIT exe below location.

Below is an Approximate path only,

C:\Users\<your name>\AppData\Local\GitHub\PortableGit_<id>/cmd 

You can set a similar above path as an environment variable to fix the issue.

References :

  • Cherry Pick in Git – Guidelines

Did I miss anything else in these resolution steps?

Did the above steps resolve your issue? Please sound off your comments below!

Happy Coding !!


Please bookmark this page and share it with your friends. Please Subscribe to the blog to get a notification on freshly published best practices and guidelines for software design and development.

Git has been a revolutionary technology and tool for every modern software developer. Version control tools let you keep track of the changes and preserve a source code snapshot if you need to revert the changes.

Whether you are working on a small or a massive software project, using a git repository to manage it can be more than beneficial.

Before using git on your system, you need to install and configure it. Git is cross-platform and can be installed on any system running Windows, macOS, or Linux.

On Windows, you may face the “git is not recognized as an internal, external command, operable program, or batch file” error even after installing git.

What causes “‘git’ is not recognized as an internal or external command, operable program or batch file.” Error?

There are three major causes of the error. These includes:

Fix #1 Git is not installed on the target system.

Before using git, you must ensure you have it installed and configured on your system. Although there are several methods of installing git on Windows, it is recommended to use the official git for Windows installer.

Open your browser and navigate to the resource below:

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

Select the installer version for your Windows system.

What do you do if git is not recognized as an internal or external command operable program or batch file?

Once the download is complete, launch the installer wizard and follow along with the installation instructions.

You can accept the default values as they work well out of the box.

Under the “Adjusting your PATH environment.”, select “Git from the command line and 3rd-party software.”

What do you do if git is not recognized as an internal or external command operable program or batch file?

The above option adds git to your PATH environment variable. This helps you access the git utility from any directory in your command prompt and any third-party software such as your code editor.

Continue with the setup wizard and complete the installation process. Once the installation is complete, open your CMD window and check the git version.

What do you do if git is not recognized as an internal or external command operable program or batch file?

Fix #2 Git is not available in the PATH environment system

Suppose you have git installed and still getting the “‘git’ is not recognized as an internal or external command, operable program or batch file.” error. In that case, the error is caused by git missing from the PATH environment variable.

You can fix that by manually adding git in your system environment variable. You can run:

setx /M path "%path%;C:\Program Files\Git\cmd"

The command above should update your system’s environment variables to include the path to the git binary.

If you are looking for a graphical method, start by navigating to the git binary in file explorer.

By default, you will find it in either of these directories.

C:\Program Files\Git\cmd

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

Select the full path in the Windows explorer path bar and click copy.

What do you do if git is not recognized as an internal or external command operable program or batch file?

Press the Windows Key + R to launch the Run dialog.

What do you do if git is not recognized as an internal or external command operable program or batch file?

Enter sysdm.cpl to launch the System properties window.

Under “Advanced,” select “Environment Variables.”

What do you do if git is not recognized as an internal or external command operable program or batch file?

Go to “System Variables” and select “Path.” Then, click on Edit to edit the Path environment variable.

What do you do if git is not recognized as an internal or external command operable program or batch file?

Click on New and paste the path you copied earlier.

What do you do if git is not recognized as an internal or external command operable program or batch file?

Click on OK to save the changes.

Once completed, launch a new terminal window and run the where git command.

What do you do if git is not recognized as an internal or external command operable program or batch file?

Fix #3 Reload Terminal Session

You will need to reload the session to update the environment variables if you have a terminal session open when installing git.

You can do this by closing and opening a new terminal session.

Closing

Using this tutorial, you discovered three significant causes of the “git command not recognized…” error. You also learned three ways to fix this error if it arises in your system.