clone parts of a github project

22,997

Solution 1

There is the subtree merge.

But here is an easier but partial solution that perhaps is good enough for your needs. Just fork and periodically merge back.

  1. Fork (clone) the repository
  2. Remove parts you do not need and move the sub-folder to where you do need
  3. Commit

In the future, when you want to sync back up with the upstream Git code, just merge it with your fork. The files which you kept will sync back up with those from upstream, and you might have some small cleanups to do which are easy to see from git status.

Solution 2

In the Git community what you want is called a “partial checkout”. It is not currently supported in Git, but it comes up every once in a while on the mailing list. Git has bits and pieces of the internals needed to support partial checkout, but there is no easy way to make use of them as a user. I would guess that Git will eventually be able to do partial checkouts, but it might be a while before it happens.

In addition to jhs's answers (subtree merge; rm, mv, commit, merge), there is also a third-party ‘subtree’ command that might help make it easier to work with partial checkouts. Though that is not its main goal, so it is not obvious how you might use it to work with a partial checkout. If you already know Git well enough, you could work it out, but if you are new to Git, this subtree command will likely be fairly opaque.

Finally, if all you want to do is download the latest files, you might be able to use git archive to download a tar file of a specific branch or tag (or any commit-ish). This may not work with GitHub (it depends on server configuration), I have not checked. Even if it does not work directly, you could clone to your own ‘bare’, mirror repo and then pull (subtree) archives from that.

Share:
22,997

Related videos on Youtube

Dennis
Author by

Dennis

developer

Updated on February 22, 2020

Comments

  • Dennis
    Dennis about 4 years

    Possible Duplicate:
    Is there any way to clone a git repository’s sub-directory only?

    I'm trying to clone parts of a github project but I can only get the root folder. This is the first time im trying to use github and I just installed tortoisegit, im used to svn and cvs where you could just take a folder you wanted to checkout, but it seems git only got a .git file in the root folder so im not sure what to do.

  • Dennis
    Dennis over 14 years
    Sounds complicated, why would someone use git over svn or cvs?
  • JasonSmith
    JasonSmith over 14 years
    In the context of GitHub, I would say that Git makes it easier to cooperate with others, both as dedicated teams or from the occasional contributor.
  • johnny
    johnny over 12 years
    This may have been added since Oct'09, but to get an archive from GitHub, there's actually a Download button in the top-right area of any repo/fork/branch/commit that will let you pull an archival copy of the code from that point in history (e.g. an earlier commit if you navigate there first)