Sormita Chakraborty
Sormita Chakraborty

Reputation: 1055

How to use curl to download a raw file in a git repository from Git hosting site?

I am trying to get a file from Git repository. I am following the examples in this link: https://docs.gitlab.com/ee/api/repository_files.html#get-file-from-repository

However, the above link is for GitLab, and I need to do this for a file on GitHub.

So using Postman and my personal access token, I am invoking the following API link: "https://github.com/xxxxxx/blob/master/abc-def/loginservicedapr-hpa.yaml?ref=master"

But I am getting a big html file as response, my actual file content is embedded in the html body. I have also tried invoking the following url: "https://github.com/xxxxxx/blob/master/abc-def/loginservicedapr-hpa.yaml/raw?ref=master"

But it is giving the same response. Please help.

Upvotes: 2

Views: 4607

Answers (1)

D Malan
D Malan

Reputation: 11464

For Github you can do:

curl \                                                                               
  -H "Accept: application/vnd.github.VERSION.raw" \
  https://api.github.com/repos/{owner}/{repo}/contents/{path}\?ref\=<ref, e.g. master>

For example, to get a file from the Laravel public repository:

curl \                                                                               
  -H "Accept: application/vnd.github.VERSION.raw" \
  https://api.github.com/repos/laravel/laravel/contents/.styleci.yml\?ref\=79fb6af96ebf0325cef15c3132157fdf75f6fd6c

Github Docs for getting repository content and custom media types.

Upvotes: 4

Related Questions