Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make git download a new folder after editing sparse-checkout?

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

like image 214
Max Williams Avatar asked Mar 27 '17 12:03

Max Williams


People also ask

How does git sparse checkout work?

"Sparse checkout" allows populating the working directory sparsely. It uses the skip-worktree bit (see git-update-index[1]) to tell Git whether a file in the working directory is worth looking at. If the skip-worktree bit is set, and the file is not present in the working tree, then its absence is ignored.

How do I disable sparse checkout?

sparseCheckout config setting. Then, run git sparse-checkout set to modify the patterns in the sparse-checkout file. To repopulate the working directory with all files, use the git sparse-checkout disable command.

How do I clone a specific directory in git?

If you want to clone the git repository into the current directory, you can do like: $ git clone <repository> . Here, the dot (.) represents the current directory.


2 Answers

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
like image 162
Andy Avatar answered Oct 06 '22 19:10

Andy


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).

like image 2
Max Williams Avatar answered Oct 06 '22 20:10

Max Williams