How to fix npm ERR! code ENOGIT npm ERR! Error while executing: npm ERR! undefined ls-remote -h -t in npm

npmBEGINNERHIGHUpdated Dec 7, 2025ยท 132 views

The ENOGIT error occurs when npm tries to install packages that depend on Git repositories, but the Git executable is not installed on your system or is not accessible via the system PATH.

Quick fix

Fixes npm ERR! code ENOGIT npm ERR! Error while executing: npm ERR! undefined ls-remote -h -t

git --version
  1. Verify Git is installed
  2. Install Git on your operating system
  3. Close and reopen your terminal
  4. Verify Git is in your PATH (Windows-specific)
npm โ€” error
git --version
npm ERR! code ENOGIT
npm ERR! Error while executing:
npm ERR! undefined ls-remote -h -t

What this error means

The ENOGIT error occurs when npm tries to install packages that depend on Git repositories, but the Git executable is not installed on your system or is not accessible via the system PATH. When npm encounters a package with a Git repository URL as a dependency (e.g., git://github.com/user/project.git), it attempts to use the git command-line tool to clone the repository. If Git is missing or not properly configured in your environment variables, npm fails with "Error while executing: undefined ls-remote". The "undefined" in the error message indicates npm tried to call the git binary but couldn't find it.

Typical symptoms

  • npm install fails with 'npm ERR! code ENOGIT'
  • Error message shows 'Error while executing: undefined ls-remote'
  • Installation stops when attempting to fetch a git-based dependency
  • Command prompt/terminal cannot find git when typing 'git --version'
  • Specific packages fail but others succeed (only git dependencies fail)

Common causes

  1. Git is not installed on the system at all
  2. Git is installed but not added to the system PATH environment variable
  3. Git installation is incomplete or corrupted
  4. System PATH was not updated after installing Git (requires terminal restart)
  5. Running npm from a shell that doesn't have Git in PATH
  6. Docker image doesn't include Git (especially Alpine-based Node images)

How to fix "npm ERR! code ENOGIT npm ERR! Error while executing: npm ERR! undefined ls-remote -h -t"

1Verify Git is installed

Open your terminal/command prompt and run:

bash
git --version

If you see a version number (e.g., "git version 2.40.0"), Git is installed.
If you see "git: command not found", proceed to Step 2.

2Install Git on your operating system

Choose the appropriate method for your OS:

Windows:
1. Download the Git installer from https://git-scm.com
2. Run the installer and complete the setup
3. IMPORTANT: Select "Git from Windows Command Prompt" option

macOS:

bash
brew install git
# Or install Xcode Command Line Tools:
xcode-select --install

Linux (Debian/Ubuntu):

bash
sudo apt-get update
sudo apt-get install git

Linux (Alpine):

bash
apk add --no-cache git
3Close and reopen your terminal

After installing Git, your current terminal session will not have the updated PATH.

On Windows: Close Command Prompt completely and open a new one.
On macOS/Linux: Close your terminal window or restart your shell.

This ensures that your system loads the new PATH environment variable.

4Verify Git is in your PATH (Windows-specific)

If the above steps didn't work on Windows, manually add Git to PATH:

1. Open Environment Variables:
- Press Win + X and select "System"
- Click "Advanced system settings"
- Click "Environment Variables"
- Under "System variables", find and select "Path"
- Click "Edit"

2. Add Git's bin directory (usually):
- C:\Program Files\Git\cmd

3. Click OK on all dialogs and restart your terminal

4. Verify with: git --version

5Try npm install again

Now that Git is properly installed:

bash
npm install

The installation should proceed without the ENOGIT error.

6For Docker environments, add Git to the image

If you're seeing this error during Docker builds, add Git to your Dockerfile:

For Alpine-based images:

dockerfile
FROM node:alpine
RUN apk add --no-cache git
COPY package*.json ./
RUN npm install

For Debian-based images:

dockerfile
FROM node:18
RUN apt-get update && apt-get install -y git
COPY package*.json ./
RUN npm install

The key is installing git BEFORE running npm install.

Advanced notes

Git Dependencies: npm supports installing packages directly from Git repositories using URLs like git+https://github.com/user/project.git#semver:^1.0.0. This is useful for private repositories, unreleased versions, or forks, but requires Git to be available.

PATH Resolution: The PATH environment variable is a list of directories where the OS looks for executable files. When npm tries to run "git", it searches through each directory in PATH until it finds the git executable.

CI/CD Pipelines: GitHub Actions, GitLab CI, and other CI systems typically have Git pre-installed. If builds fail there, check that the CI environment is configured correctly.

Alternative: If you don't want to install Git, consider whether the git dependency in package.json can be replaced with an npm registry package instead.

Frequently asked questions

What does "npm ERR! code ENOGIT npm ERR! Error while executing: npm ERR! undefine" mean?
The ENOGIT error occurs when npm tries to install packages that depend on Git repositories, but the Git executable is not installed on your system or is not accessible via the system PATH. git), it attempts to use the git command-line tool to clone the repository. If Git is missing or not properly configured in your environment variables, npm fails with "Error while executing: undefined ls-remote".
How do I fix "npm ERR! code ENOGIT npm ERR! Error while executing: npm ERR! undefine"?
The ENOGIT error occurs when npm tries to install packages that depend on Git repositories, but the Git executable is not installed on your system or is not accessible via the system PATH.
What causes "npm ERR! code ENOGIT npm ERR! Error while executing: npm ERR! undefine"?
Git is not installed on the system at all Git is installed but not added to the system PATH environment variable Git installation is incomplete or corrupted
Is the "npm ERR! code ENOGIT npm ERR! Error while executing: npm ERR! undefine" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading