sps
sps

Reputation: 2720

How to copy only one file from a GitHub repository to local machine?

I have a repository on GitHub which has the code of a project that I am working on.

While working, I deleted a file from my local machine. So, now I want to copy the file from my GitHub repository to my local machine.

Initially I thought I should clone the repository and then copy the required file locally in my machine.

But is there a way to get only one file without having to clone the entire repository? Preferably from the command line ? (just like how we clone from CLI using git clone ...)

Upvotes: 2

Views: 5517

Answers (1)

Petr Skocik
Petr Skocik

Reputation: 60107

The way git repos work is you have the working tree and in it a .git directory that contains a database with your project's history. When you delete from the working tree, you can do git checkout -- FILE and git will go to that database and retrieve the latest version of the file (given the branch you're at). You can delete anything in your working tree and as long as it once was committed to the database in .git (and kept there), it is immediately recoverable.

I recommend you read up or take a course on some basics of git. Take a look at https://www.codeschool.com/paths/git and http://www.git-scm.com/book/en/v2 .

Upvotes: 3

Related Questions