pip install from git repository

2025-04-14 (updated 2025-10-25)
Notes | 1 min read
#git #pip #python

Install a pip package from a git repo, using a specified git reference:

$REPOSITORY = "https://gitlab.com/mkamner/example.git"
$GIT_REF = "my-branch-or-tag-or-sha"

pip install "git+$REPOSITORY/@$GIT_REF"

If the package resides in a sub-directory this can be specified like this:

$REPOSITORY = "https://gitlab.com/mkamner/example.git"
$GIT_REF = "my-branch-or-tag-or-sha"
$DIRECTORY = "my-folder"

pip install "git+$REPOSITORY/@$GIT_REF#subdirectory=$DIRECTORY"