0

I am wondering if I can clone a portion of a repository on github using a HTTPS git url.

For example, if I have the following url for the overall repository:

https://github.com/bob/thisrepository.git

But, I only want what's inside this repository by one folder to clone. So, for instance:

https://github.com/bob/thisrepository/tree/master/laravel-master.git

Would this work in something like rocketeer? Thank you.

user1072337
  • 12,615
  • 37
  • 116
  • 195
  • Is `https://github.com/bob/thisrepository/tree/master/laravel-master.git` a submodule (i.e. another Git repo) inside of the `https://github.com/bob/thisrepository.git` repo? –  May 05 '14 at 17:35
  • Possible duplicate of [Is there any way to clone a git repository's sub-directory only?](http://stackoverflow.com/questions/600079/is-there-any-way-to-clone-a-git-repositorys-sub-directory-only) –  May 05 '14 at 17:35

1 Answers1

1

This isn't possible because a git repository contains a whole entire projects contents and changes. If you took one directory, then each commit would potentially have a different subset of changes, making the signature of each commit different (you could probably write a script that does this for you, but its not how git is meant to work).

Instead, you would have to download the directory and initialize a new git repository with it. Currently, GitHub only lets you download an entire branch's (or commit's) repository as a ZIP archive. So something like this:

# Download and extract archive
wget https://github.com/bob/thisrepository/archive/master.zip
unzip master.zip

# Copy subdirectory out of repo
cp -r thisrepository-master/path/to/subdirectory /path/to/new/project

# Create a new git repo
cd /path/to/new/project
git init
git add .
git commit -m "intial commit"

Bonus:

Check out this answer for information on git-archive and how you can use that to extract the sub-directory directly from GitHub, rather than downloading the whole repo and extracting (you'll still need to initialize a new repository based off of the files).

Community
  • 1
  • 1
Sam
  • 20,096
  • 2
  • 45
  • 71