Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using curl, how do I download a .diff file from a private repository on github

Tags:

github

curl

I have a private repo on github, belonging to an org. For a given pull request, there's a url to a diff file like this:

https://github.com/<ORG>/<REPO>/pull/<PR_NUMBER>.diff

But the repo is private, so how can I download this file with curl? I generated a "personal access token", but am a bit lost as to how to use it.

I tried this:

curl -H 'Authorization: token <TOKEN>' -H 'Accept: application/vnd.github.v3.raw' -O -L "https://github.com/<ORG>/<REPO>/pull/<PR_NUMBER>.diff"

But all that sent back was "Not Found".

like image 598
polytopia Avatar asked Feb 18 '16 01:02

polytopia


People also ask

How do I read RAW files from GitHub?

On GitHub.com, navigate to the main page of the repository. Click the file that you want to view. In the upper-right corner of the file view, click Raw.


1 Answers

You can use the pull request url from api.github.com with different accept content type. e.g.

curl -H 'Authorization: token mytoken' -H "Accept: application/vnd.github.v3.diff" https://api.github.com/repos/orgname/repo/pulls/1234

Notice: Please remove ".diff" suffix from the url.

like image 91
c9s Avatar answered Oct 23 '22 01:10

c9s