304

I'm developing a django app and I'm using pip to manage my requirements. How can I do to install a specific git's commit?

In my case I need to install this commit: https://github.com/aladagemre/django-notification/commit/2927346f4c513a217ac8ad076e494dd1adbf70e1

4 Answers 4

523

You can specify commit hash, branch name, tag.

For the branch name and the tag, you can also install a compressed distribution. This is faster and more efficient, as it does not require cloning the entire repository. GitHub creates those bundles automatically.

hash:

$ pip install git+https://github.com/aladagemre/django-notification.git@2927346f4c513a217ac8ad076e494dd1adbf70e1

branch-name

With git

$ pip install git+https://github.com/aladagemre/django-notification.git@cool-feature-branch

or from source bundle

$ pip install https://github.com/aladagemre/django-notification/archive/cool-feature-branch.tar.gz

tag

with git

$ pip install git+https://github.com/aladagemre/[email protected]

or from source bundle

$ pip install https://github.com/aladagemre/django-notification/archive/v2.1.0.tar.gz

It is a not well-documented feature, but you can find more information at https://pip.pypa.io/en/latest/topics/vcs-support/

Sign up to request clarification or add additional context in comments.

9 Comments

It will add this fun message: Could not find a tag or branch '2927346f4c513a217ac8ad076e494dd1adbf70e1', assuming commit.
@vlad-ardelean any idea on how to tell pip IT IS a commit? This is getting outputed on my deploy script and I don't want to suppress all stderr.
@ScottStafford You should not have a branch / tag which is called like a commit message. That would be ... strange.
In addition I would mention a HTTPS version of git+ command: pip install git+https://github.com/gpoore/codebraid@011464539bfb09b8611c8aef0d543532cea958bf. It may be important for people behind corporate http proxies.
@LeonardoArroyo that warning is no longer printed as long as you use the full 40 character hash with recent versions of pip. See: github.com/pypa/pip/pull/4674
|
34

It's possible to automatically install a python package using the requirements.txt file on you project just by adding the following line:

package-name -e git+https://github.com/owner/repository.git@branch_or_commit#egg={package-name}

and run the command line:

$ pip install -r requirements.txt

6 Comments

For me (pip 9.0.1 in python3.5 virtualenv ) it didn't work : pip install -r requirements.txt raised 'Could not detect requirement name, please specify one with #egg='. But it worked with the format '-e git+github.com/owner/repository.git#egg=branch_or_commit'
You need to use this format inside the requirements.txt file. Did you do that?
I got it working but this is unclear. Need to have "package_name -e ..." and not just "-e ..." at the start of the line.
The package -e url syntax was not working for me. I'm guessing this was meant to signify an editable build but, well, it was not installing from Github when I tried this. Merely specifying the actual git+https://github.com/... URL like in the accepted answer worked for me with pip 19.2.3 on Python 3.8.2
package-name -e url syntax was harmful for me on Py3.10. it silently ignored the url I provided, and installed package-name latest PyPi version. what worked for me instead was to omit package name entirely, à la -e git+https://github.com/EleutherAI/lm-evaluation-harness.git@568af943e315100af3f00937bfd6947844769ab8#egg=lm_eval
|
26

An extra comment to @hugo-tavares's answer:

If it's a private GitHub repository, you'll need to use:

pip install git+ssh://[email protected]/....

In your case:

pip install git+ssh://[email protected]/aladagemre/django-notification.git@2927346f4c513a217ac8ad076e494dd1adbf70e1

Comments

4

If you want to create an egg package, you can still use the same @branch_or_commit appendage: pip install git+ssh://[email protected]/myrepo.git@mybranch#egg=myeggscript

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.