views:

327

answers:

3

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.

+1  A: 

There is the subtree merge.

But her 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.

jhs
Sounds complicated, why would someone use git over svn or cvs?
Dennis
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.
jhs
+3  A: 

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.

Chris Johnsen
+1  A: 

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.

Xiong Chiamiov