2

I am trying to effectively check out only a directory and its contents (a specific wordpress theme directory) inside a larger git repo hosted on Github on a server. The server has existing WordPress directories in it, and I want to place the new theme directory from the repo into the proper directory on the server. I first tried the approach described in an accepted answer to a similar question. When I ran the below line,

[scapa]$ git fetch git@github.com:mrengy/new-urban-arts.git

I got an error of:

fatal: Not a git repository (or any parent up to mount parent ) Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set).

So I ran:

[scapa]$ git init
Initialized empty Git repository in /home/newurbanarts/stage.newurbanarts.org/.git/
[scapa]$ git remote add origin git@github.com:mrengy/new-urban-arts.git

Now when I run (as per the accepted answer):

[scapa]$ git fetch origin master    
[scapa]$ git checkout origin/master -- wp-content/themes/newurbanarts

I get:

error: pathspec 'wp-content/themes/newurbanarts' did not match any file(s) known to git.

What am I doing wrong, and how do I get around this?

Community
  • 1
  • 1
Mike Eng
  • 1,593
  • 4
  • 34
  • 53
  • What is the output of git log? – Grisk Aug 06 '15 at 03:06
  • @Grisk fatal: bad default revision 'HEAD' – Mike Eng Aug 06 '15 at 13:22
  • Sounds like the local head is just corrupt. Have you deleted .git and tried it again? – Grisk Aug 06 '15 at 13:23
  • @Grisk Okay, I deleted .git and again ran the lines exactly as above in the question. When I ran `git fetch origin master`, the response was "From github.com:mrengy/new-urban-arts * branch master -> FETCH_HEAD". Then when I ran `git checkout origin/master -- wp-content/themes/newurbanarts` , the response was "fatal: invalid reference: origin/master" – Mike Eng Aug 10 '15 at 13:48
  • 1
    Did you clone the repo or did you manually init and fetch? It sounds like you never pulled down the branch contents. Also, you'll need to create a remote tracking branch before you can do anything. – Grisk Aug 10 '15 at 13:50
  • @Grisk I did not clone the repo. I manually did init and fetch. The repo has a bunch of content that would overwrite other existing content on the server. So I only want to get a specific directory from the repo into the server. What exactly do I need to do to pull down the branch contents and create a remote tracking branch in this situation? – Mike Eng Aug 10 '15 at 13:58
  • 1
    http://stackoverflow.com/questions/600079/is-there-any-way-to-clone-a-git-repositorys-sub-directory-only/13738951#13738951 – Grisk Aug 10 '15 at 13:59
  • Whoops, didn't mean to comment just the url. Those should be the steps that you need. – Grisk Aug 10 '15 at 14:00

1 Answers1

2

So after some back and forth in the comments, I think we've come to a solution here.

As it turns out, GIT does support the concept of checking out only subtrees of a given repository, through a process called 'sparse checkout' which you can find more information about here.

The concept is to initialize a new, clean git repository, add your remotes, turn on the setting 'core.sparsecheckout,' and finally to check out your folders.

Community
  • 1
  • 1
Grisk
  • 328
  • 2
  • 13