8

I have a git repo where I only want to download certain subfolders. My config looks like this:

#.git/config

[core]
    repositoryformatversion = 0
    filemode = true
    bare = false
    logallrefupdates = true
    sparsecheckout = true
[remote "dreamhost"]
  url = <repo url>
  fetch = +refs/heads/*:refs/remotes/dreamhost/*
[push]
  default = tracking  

In .git/info/sparse-checkout i had this:

themes/theme1
themes/theme8

which are the folders within the themes subfolder that I want to get. (I don't need the others, which are many).

If i do a git/pull I can see git fetching lots of stuff, including the themes subfolders which I don't want, which is fine. I know that sparse-checkout still pulls down the objects.

I now want to have a copy of themes/theme15, to make some changes. So, I edited .git/info/sparse-checkout thus:

themes/theme1
themes/theme8
themes/theme15

and then did a git pull dreamhost master, thinking that git would add the theme15 folder under themes. But, nothing happens - it just says

From <repo url>
 * branch            master     -> FETCH_HEAD
Already up-to-date.

and the folder's not there. Can anyone tell me what I'm doing wrong? Is there an extra step after editing .git/info/sparse-checkout?

thanks, Max

EDIT: this is in git version 2.8.1 btw

Max Williams
  • 32,435
  • 31
  • 130
  • 197

4 Answers4

18

The step I needed to perform to make my folder appear after adding it to my sparse-checkout file was:

git read-tree -mu HEAD
Andy
  • 171
  • 1
  • 4
2

This worked for me

git sparse-checkout reapply
sarema
  • 695
  • 5
  • 18
  • Please don't add "thank you" as an answer. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation), you will be able to [vote up questions and answers](https://stackoverflow.com/help/privileges/vote-up) that you found helpful. - [From Review](/review/late-answers/30849755) – Simas Joneliunas Jan 23 '22 at 07:24
1

Just figured this out, I'll answer it in case anyone else has the same problem.

After making the change I needed to do

git checkout themes/theme15

then the folder appears. Perhaps obvious in hindsight....(perhaps not).

Max Williams
  • 32,435
  • 31
  • 130
  • 197
0

Since git 2.25 there's a new command, git sparse-checkout, intended to help with these flows (so you generally wouldn't edit the .git/info/sparse-checkout file, or change the core.sparsecheckout setting manually anymore).

It's still experimental as of git 2.27, so might change in exact functionality & syntax.

Doc: https://git-scm.com/docs/git-sparse-checkout

Tao
  • 13,457
  • 7
  • 65
  • 76