Safeguard
Supply Chain•

Should you block git dependencies with npm's allow-git setting?

npm's allow-git config can restrict git references to none or root only. When to use it, what it does not change, and how to roll it out safely.

Safeguard Security Team
3 min read

For most application teams, yes: set allow-git to root or none. The npm config reference describes it as a source restriction on whether npm fetches dependencies from git references. With root, only git dependencies in your own package.json are allowed, so a transitive package cannot pull code from a repository.

What the setting does

According to the npm config reference, allow-git defaults to all and accepts three values:

ValueEffect
allAny git dependency is allowed. This is the default
rootOnly git dependencies declared in the project's own package.json are allowed
noneGit dependencies are blocked

The page also says changing it does not remove dependencies that are already installed. It is a source restriction, not an install script allow list. Confirm the setting exists in your npm version, because the reference does not give the release in which it was added.

Why git sources are different

A package from the registry has a published version, a checksum in the lockfile, and a place in the registry's history. A git reference may point at a branch or tag that can move. Even when a lockfile records a commit, reviewers have a harder time seeing what changed, and the code was not published through the registry's publishing controls. A transitive dependency that points at a git repository adds a source you may never have reviewed.

This is also a way for build time code to appear. Packages fetched from git can run a prepare step during install. The npm approve-scripts docs list prepare for non registry dependencies among the lifecycle scripts the allow policy covers, which shows why git sources deserve extra care.

How to roll it out

  1. Find current git dependencies. Search the lockfile for entries whose resolved field points at a git URL, or run npm ls --all and look for git sources.
  2. Decide for each: replace with a registry release, pin to a full commit hash, or keep and document why.
  3. Set allow-git=root in the project .npmrc and run a clean install in CI.
  4. If the install fails, the error tells you which transitive package needs a git source. Decide whether to override it or replace the parent.
  5. Move to none if no git dependencies remain.
  6. Commit the .npmrc so every developer and CI job uses the same setting.

Things to watch

Pin any git dependency you keep to a full commit hash, not a branch name. Use npm overrides where a transitive package needs replacing. Remember that the setting only governs how npm fetches, and other package managers have their own options.

What it does not protect against

A registry package can still be malicious, so keep scanning. This setting reduces one source of surprise, in the same family as reviewing install scripts and a release delay.

Safeguard dependency scanning reports each package in your tree along with its source, and you can start with a free scan.

Quick check

Does allow-git remove git dependencies that are already installed?

No. The npm docs say changing it does not remove dependencies already installed.

What is the default value?

all, which permits any git dependency.

Sources

Last reviewed: 19 October 2026.

Never miss an update

Weekly insights on software supply chain security, delivered to your inbox.

Self-healing security runs on Safeguard.

Your first fix PR is minutes away.

No sales call required, even your agent can complete the purchase over MCP.