Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check out a single file from GitHub without cloning the whole repository?

Tags:

github

On a production machine I want to check out a specific file at a specific revision from GitHub to facilitate database migration. I don't want to checkout (or even clone) the whole source code repository (because this is my production environment). How can I pull only the file I am looking for?

like image 342
Niel de Wet Avatar asked Sep 08 '11 06:09

Niel de Wet


2 Answers

I do this with for backbones like so

curl -O https://raw.github.com/documentcloud/backbone/master/backbone-min.js
like image 101
Kevin Avatar answered Jan 04 '23 04:01

Kevin


My solution is like in first post. But I try to explain a bit more. There is a "Raw" button on GitHub for every file - it will show just plain text in browser. Also, you can use that url.

For example, I have repo https://github.com/MasterSergius/conf_files.git And I want to get my .vimrc file, so here the link to my file: https://raw.githubusercontent.com/MasterSergius/conf_files/master/.vimrc I do think, that by this template you even can guess file url by repo and file full pathname. So, now I can download it with curl:

curl https://raw.githubusercontent.com/MasterSergius/conf_files/master/.vimrc -o ~/.vimrc
like image 24
Sergius Avatar answered Jan 04 '23 04:01

Sergius