Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clone parts of a github project [duplicate]

Tags:

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.

like image 571
Dennis Avatar asked Oct 24 '09 13:10

Dennis


People also ask

How do I duplicate a project in GitHub?

On the top-right side of the classic project, click Menu. Click , then click Copy. Under "Owner", use the drop-down menu and click the repository or organization where you want to copy the project board. Optionally, under "Project board name", type the name of the copied classic project.

How do I clone a specific folder from a git repository?

In your test repository try creating an additional file at the top level. If you follow your instructions, then you'll also get a copy of that file as well as the directory you want. Remove the 'git sparse-checkout init --cone' but follow all your other instructions, and you'll just get the directory tree you want.

Will git clone copy all the branches?

The idea is to use the git-clone to clone the repository. This will automatically fetch all the branches and tags in the cloned repository. To check out the specific branch, you can use the git-checkout command to create a local tracking branch.

How do I mirror a GitHub repository?

Navigate to the repository you just cloned. Pull in the repository's Git Large File Storage objects. Mirror-push to the new repository. Push the repository's Git Large File Storage objects to your mirror.


2 Answers

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.

like image 199
JasonSmith Avatar answered Sep 28 '22 00:09

JasonSmith


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.

like image 39
Chris Johnsen Avatar answered Sep 28 '22 02:09

Chris Johnsen