clone parts of a github project [duplicate]
Asked Answered
D

3

25

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.

Doctrine answered 24/10, 2009 at 13:35 Comment(2)
It seems strange that you only got the .git directory. Did you clone the repository correctly?Caelum
I think you misunderstood me, I get all the files but I only want a subfolder of the project.Doctrine
H
8

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.

Hydnocarpate answered 24/10, 2009 at 13:52 Comment(2)
Sounds complicated, why would someone use git over svn or cvs?Doctrine
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.Hydnocarpate
B
7

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.

Barnes answered 27/10, 2009 at 9:11 Comment(1)
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)Hanley
S
-1

This isn't really something that you do in git. Remember, you're using a DVCS, so you're pulling down entire repository history - what is supposed to happen to the commits that change files outside the directory you're pulling down?

If a project is sufficiently large, then the maintainer of whatever repo you're cloning should use submodules to divide up the sections, so that developers can only pull down the areas they want to work on.

Git (well, DVCSs in general) is not designed for endusers so much as it is for developers. I find git (especially in combination with github) to be incredibly helpful for coding. If there's a project on github that I want to contribute to, I just fork it, pull it down, hackhackhack, push up, and send a pull request, easypeasy, rather than making a checkout, hacking, creating a diff, trying to find where to email it to, and hoping that the diff doesn't break before the developers get around to merging it in.

Git as a whole is certainly more complicated than svn, but that's because coding is a complicated process. The centralized VCS workflow is incredibly painful for me, because I was raised on DVCSs, and I'm not allowed to do all sorts of things that I'm used to doing. So, yes, it will be more complicated to use git vs. svn if you do the same things, but the advantage is that there are so many more things that you can do. Git was developed for linux kernel development, and it shows.

Smog answered 3/11, 2009 at 19:58 Comment(1)
I don't see why it shouldn't be something provided by git. The request, "give me all files matching /foo/bar/.* at commit 6789abc", is well-defined and useful.Hedjaz

© 2022 - 2024 — McMap. All rights reserved.