How to pip install From a Git Repository

You can install a Python package from a Git repository by running the pip install git+ command followed by the URL of the repository. For example, to install the Requests module from its GitHub repository:

pip install git+https://github.com/psf/requests.git

This requires Git installed, since the git command is executed within a subprocess.

If you want to install a specific commit, add @ (at symbol) followed by the commit hash, for example:

pip install git+https://github.com/psf/requests.git@15585909c3dd3014e4083961c8a404709450151c

You might also specify a branch or tag:

pip install git+https://github.com/psf/requests.git@v2.27.x

If you need to install from a private GitHub repository for which you have a private access token (PAT), use:

pip install git+https://MY_GITHUB_USER:MY_GITHUB_TOKEN@github.com/user/repository.git

(Replace MY_GITHUB_USER and MY_GITHUB_TOKEN with the proper values.)

If, for security reasons, the GitHub user and token are stored in environment variables (e.g. in GITHUB_USER and GITHUB_TOKEN), you can inject these variables as follows.

pip install git+https://$GITHUB_USER:$GITHUB_TOKEN@github.com/user/repository.git