I wanted to clone a sub directory https://github.com/CoreyMSchafer/code_snippets/tree/master/Django_Blog/12-Password-Reset/django_project
from the parent directory
https://github.com/CoreyMSchafer/code_snippets.git
I have gone through some Stack Overflow answers and they say that Git is not designed to download specific files from root folder.
I tried below commands in my cmd
git clone https://github.com/CoreyMSchafer/code_snippets.git -b code_snippets/tree/master/Django_Blog/12-Password-Reset/django_project but it did not work out.
if this might be a possible duplicate question.
There is a difference between cloning the whole repo and downloading. When you say cloning, this means that you're interested in all the history, meaning what happened to the file as the repository has evolved. I don't think its possible with git because its not designed to do so. I'll be glad to be proven otherwise though.
If you want, however, to "just download" the last "snapshot" of the file (which I assume what you really want), then you have a couple of options:
git archive --remote=ssh://<address>/repo.git <BranchName|HEAD> /some/path/file.txt | tar -xO /some/path/file.txt > /tmp/file.txt
Read This thread in SO for more information/ ideas
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With