{"id":367348,"date":"2021-11-15T15:00:57","date_gmt":"2021-11-15T12:00:57","guid":{"rendered":"https:\/\/en.buradabiliyorum.com\/how-to-download-single-files-from-a-github-repository-cloudsavvy-it\/"},"modified":"2021-11-15T15:00:57","modified_gmt":"2021-11-15T12:00:57","slug":"how-to-download-single-files-from-a-github-repository-cloudsavvy-it","status":"publish","type":"post","link":"https:\/\/buradabiliyorum.com\/en\/how-to-download-single-files-from-a-github-repository-cloudsavvy-it\/","title":{"rendered":"#How To Download Single Files From a Github Repository \u2013 CloudSavvy IT"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_85 counter-hierarchy ez-toc-counter ez-toc-custom ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6a3dca17ef6aa\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #dd3333;color:#dd3333\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #dd3333;color:#dd3333\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6a3dca17ef6aa\" checked aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-download-single-files-from-a-github-repository-cloudsavvy-it\/#Downloading_a_Single_File_From_The_Github_Website\" >Downloading a Single File From The Github Website<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/buradabiliyorum.com\/en\/how-to-download-single-files-from-a-github-repository-cloudsavvy-it\/#Downloading_From_The_Command_Line\" >Downloading From The Command Line<\/a><\/li><\/ul><\/nav><\/div>\n<p><strong>&#8220;#How To <a href=\"https:\/\/buradabiliyorum.com\/en\/category\/download-scripts-themes-apps\/\" data-internallinksmanager029f6b8e52c=\"9\" title=\"Download Scripts &amp; Themes &amp; Apps\" target=\"_blank\" rel=\"noopener\">Download<\/a> Single Files From a Github Repository \u2013 CloudSavvy IT&#8221;<\/strong><\/p>\n<div id=\"article-content-area\">\n<img loading=\"lazy\" decoding=\"async\" class=\"type:primaryImage alignnone size-full wp-image-7125\" srcset=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/10\/d6528811.png?width=398&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 400w, https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/10\/d6528811.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1 1200w\" sizes=\"auto, 400w, 1200w\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/10\/d6528811.png?width=1198&amp;trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"700\" height=\"300\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>While Github is most commonly used to host large code projects, it also functions as a pretty good file host, and sometimes you just want to download a file or two without cloning the entire repo. Github supports this, both from the site and command line.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Downloading_a_Single_File_From_The_Github_Website\"><\/span>Downloading a Single File From The Github Website<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>If you\u2019re fine using your web browser, you can download single files pretty easily. Head over to the file you want to download and click \u201cRaw:\u201d<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14659\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/0ad2a42a.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"625\" height=\"278\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>This will open up a page with a direct link to the file. You can copy\/paste from here, but in most browsers, you should be able to right click and select \u201cSave As\u201d to download the file directly.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-14660\" src=\"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2021\/11\/fba73191.png?trim=1,1&amp;bg-color=000&amp;pad=1,1\" alt=\"\" width=\"543\" height=\"244\" onload=\"pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\" onerror=\"this.onerror=null;pagespeed.lazyLoadImages.loadIfVisibleAndMaybeBeacon(this);\"\/><\/p>\n<p>For code files, it may try to save as <code>.txt<\/code>, which you will need to fix manually before or after downloading.<\/p>\n<h2 role=\"heading\" aria-level=\"2\"><span class=\"ez-toc-section\" id=\"Downloading_From_The_Command_Line\"><\/span>Downloading From The Command Line<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Since files served from <code>raw.githubusercontent.com<\/code>, you can download them directly through <code>wget<\/code>\u00a0or <code>curl<\/code>. They\u2019re stored in accessible locations, so if you know the username, repository, and file path, you can download any file on any branch like so:<\/p>\n<pre>wget\u00a0https:\/\/raw.githubusercontent.com\/username\/repository\/branch\/path\/filename.md<\/pre>\n<p>If you\u2019d rather use Git\u2019s API, you can interact with it more directly, and download files when you aren\u2019t sure of the exact file location.\u00a0You will need to<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.github.com\/en\/authentication\/keeping-your-account-and-data-secure\/creating-a-personal-access-token\"> create a personal access token to use the API<\/a>, with which you can replace \u201cACCESS_TOKEN\u201d in this script.<\/p>\n<pre>curl -H 'Authorization: token ACCESS_TOKEN ' -H &#13;\n'Accept: application\/vnd.github.v3.raw' -O -L &#13;\nhttps:\/\/api.github.com\/repos\/username\/repository\/contents\/path\/filename.md<\/pre>\n<p>The\u00a0<a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.github.com\/en\/rest\/reference\/repos#contents\">\/<code>repos\/{user}\/{repo}\/contents<\/code>\u00a0endpoint<\/a> will do a different things depending on whether the path points to a directory or a file. If it\u2019s a file, it will return metadata about that file:<\/p>\n<pre>{&#13;\n  \"type\": \"file\",&#13;\n  \"encoding\": \"base64\",&#13;\n  \"size\": 5362,&#13;\n  \"name\": \"README.md\",&#13;\n  \"path\": \"README.md\",&#13;\n  \"content\": \"encoded content ...\",&#13;\n  \"sha\": \"3d21ec53a331a6f037a91c368710b99387d012c1\",&#13;\n  \"url\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/contents\/README.md\",&#13;\n  \"git_url\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/git\/blobs\/3d21ec53a331a6f037a91c368710b99387d012c1\",&#13;\n  \"html_url\": \"https:\/\/github.com\/octokit\/octokit.rb\/blob\/master\/README.md\",&#13;\n  \"download_url\": \"https:\/\/raw.githubusercontent.com\/octokit\/octokit.rb\/master\/README.md\",&#13;\n  \"_links\": {&#13;\n    \"git\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/git\/blobs\/3d21ec53a331a6f037a91c368710b99387d012c1\",&#13;\n    \"self\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/contents\/README.md\",&#13;\n    \"html\": \"https:\/\/github.com\/octokit\/octokit.rb\/blob\/master\/README.md\"&#13;\n  }&#13;\n}<\/pre>\n<p>If it\u2019s a directory, it will return all the files and subdirectories in an array:<\/p>\n<pre>[&#13;\n  {&#13;\n    \"type\": \"file\",&#13;\n    \"size\": 625,&#13;\n    \"name\": \"octokit.rb\",&#13;\n    \"path\": \"lib\/octokit.rb\",&#13;\n    \"sha\": \"fff6fe3a23bf1c8ea0692b4a883af99bee26fd3b\",&#13;\n    \"url\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/contents\/lib\/octokit.rb\",&#13;\n    \"git_url\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/git\/blobs\/fff6fe3a23bf1c8ea0692b4a883af99bee26fd3b\",&#13;\n    \"html_url\": \"https:\/\/github.com\/octokit\/octokit.rb\/blob\/master\/lib\/octokit.rb\",&#13;\n    \"download_url\": \"https:\/\/raw.githubusercontent.com\/octokit\/octokit.rb\/master\/lib\/octokit.rb\",&#13;\n    \"_links\": {&#13;\n      \"self\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/contents\/lib\/octokit.rb\",&#13;\n      \"git\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/git\/blobs\/fff6fe3a23bf1c8ea0692b4a883af99bee26fd3b\",&#13;\n      \"html\": \"https:\/\/github.com\/octokit\/octokit.rb\/blob\/master\/lib\/octokit.rb\"&#13;\n    }&#13;\n  },&#13;\n  {&#13;\n    \"type\": \"dir\",&#13;\n    \"size\": 0,&#13;\n    \"name\": \"octokit\",&#13;\n    \"path\": \"lib\/octokit\",&#13;\n    \"sha\": \"a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d\",&#13;\n    \"url\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/contents\/lib\/octokit\",&#13;\n    \"git_url\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/git\/trees\/a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d\",&#13;\n    \"html_url\": \"https:\/\/github.com\/octokit\/octokit.rb\/tree\/master\/lib\/octokit\",&#13;\n    \"download_url\": null,&#13;\n    \"_links\": {&#13;\n      \"self\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/contents\/lib\/octokit\",&#13;\n      \"git\": \"https:\/\/api.github.com\/repos\/octokit\/octokit.rb\/git\/trees\/a84d88e7554fc1fa21bcbc4efae3c782a70d2b9d\",&#13;\n      \"html\": \"https:\/\/github.com\/octokit\/octokit.rb\/tree\/master\/lib\/octokit\"&#13;\n    }&#13;\n  }&#13;\n]<\/pre>\n<p>You can then use a JSON parser like jq to pull out the URL and download it. To get the repository file list recursively, <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.github.com\/en\/rest\/reference\/git#trees\">you will need to fetch the root tree<\/a>.<\/p>\n<p><strong>RELATED:<\/strong> <strong><em>How to Work With JSON On the Command Line<\/em><\/strong>\n<\/div>\n<blockquote><p><strong><span style=\"color: #ff6600;\">If you liked the article, do not forget to share it with your friends. Follow us on\u00a0<span style=\"color: #ff0000;\"><a style=\"color: #ff0000;\" href=\"https:\/\/news.google.com\/publications\/CAAqBwgKMLG0nwswvr63Aw\" target=\"_blank\" rel=\"nofollow noopener noreferrer\">Google News<\/a><\/span>\u00a0too, click on the star and choose us from your favorites.<\/span><\/strong><\/p><\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\">For forums sites go to <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/forum.buradabiliyorum.com\/\" target=\"_blank\" rel=\"noopener\">Forum.BuradaBiliyorum.Com<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<blockquote>\n<p style=\"text-align: center;\"><strong>If you want to read more like this article, you can visit our <span style=\"color: #ff9900;\"><a style=\"color: #ff9900;\" href=\"https:\/\/en.buradabiliyorum.com\/technology\/\" target=\"_blank\" rel=\"noopener\">Technology category.<\/a><\/span><\/strong><\/p>\n<\/blockquote>\n<p><span style=\"color: black;\"><a style=\"color: #ff9900;\" href=\"https:\/\/www.cloudsavvyit.com\/14656\/how-to-download-single-files-from-a-github-repository\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>&#8220;#How To Download Single Files From a Github Repository \u2013 CloudSavvy IT&#8221; While Github is most commonly used to host large code projects, it also functions as a pretty good file host, and sometimes you just want to download a file or two without cloning the entire repo. Github supports this, both from the site&#8230;<\/p>\n","protected":false},"author":1,"featured_media":367349,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"fifu_image_url":"https:\/\/www.cloudsavvyit.com\/p\/uploads\/2020\/10\/d6528811.png","fifu_image_alt":"","footnotes":""},"categories":[18],"tags":[],"class_list":["post-367348","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-technology"],"_links":{"self":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/367348","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/comments?post=367348"}],"version-history":[{"count":0,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/posts\/367348\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media\/367349"}],"wp:attachment":[{"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/media?parent=367348"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/categories?post=367348"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/buradabiliyorum.com\/en\/wp-json\/wp\/v2\/tags?post=367348"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}