Safeguard
Developer Tools•

How do you pin a pip dependency from Git to an exact commit?

Install from a Git URL in a requirements file, and pin with a full commit hash instead of a branch or tag so the code cannot change under you.

Safeguard Security Team
3 min read

Write the requirement as a name, an at sign, and a git plus https URL, then end the URL with an at sign and the full 40 character commit hash. A branch name follows new pushes, and a tag can be recreated, but a commit hash names one exact snapshot of the code.

The syntax pip supports

pip's documentation gives the general form as the project name, an at sign, then the version control URL. For Git the supported schemes include git plus https and git plus ssh. It discourages the plain git, git plus git and git plus http schemes, because the Git protocol has no authentication and HTTP is not encrypted.

After the URL you can add an at sign and a Git reference. The documentation shows a branch, a tag, a full commit hash and a pull request reference as valid examples. It recommends a full hash over a partial one because pip can work more efficiently.

MyProject @ git+https://git.example.com/MyProject.git@da39a3ee5e6b4b0d3255bfef95601890afd80709

Why the reference you choose matters

ReferenceFixed over time?
Branch such as mainNo, moves with every push
Tag such as v1.0Usually, but a tag can be deleted and recreated
Full commit hashYes, it names one commit

The pip page shows the syntax but does not make a claim about movement, so this table reflects how Git works in general rather than a pip guarantee.

Steps

  1. Find the commit you reviewed in the repository history.
  2. Copy the full hash, not an abbreviation.
  3. Put it in the requirement as shown above.
  4. Record in a comment why the project uses Git instead of a registry release.
  5. Revisit when a normal release appears.

Things a commit pin does not fix

Pinning the commit does not review the code. Also, the repository itself can disappear, move, or be taken over by someone else. Consider mirroring any Git dependency you cannot live without into a repository you control. Hash checking in pip needs a URL or a pinned version, so a Git dependency fits only when you pin it as above.

When a Git dependency is a warning sign

Most projects that depend on a Git URL do so because a fix is not yet released, or because the code is internal. Both are fine, but each deserves a note. A fix that is not released may be unreviewed, and an internal repository needs the same access controls as the rest of your source. If the dependency is third party and has been on a commit pin for months, ask whether a release now exists and whether the maintainer is still active.

Also watch how the code gets built. A Git install builds from source on your machine, so any build step in that repository runs during install.

Quick check

Is a tag safe enough to pin to?

It is better than a branch, but a commit hash is the exact option. Prefer the hash.

Can I use a short commit hash?

pip accepts it, but its documentation prefers a full hash for efficiency and clarity.

Safeguard's dependency scanning lists direct and transitive components in an SBOM, so Git sourced packages show up in the inventory. A free scan is open to try.

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.