On August 25, 2020, I learned...

How to clone just the contents of a GitHub repository

Don’t laugh. I’m a complete Git noob. I needed to clone a WordPress project locally and repo was just the wp-content directory of the site.

If I cloned this normally, it would install the entire repo to my machine, including the top-level root directory. But what I needed was just the contents of that directory so that I could use it with a standard WordPress installation.

The trick? Well, two approaches will do. The first is to cd into a completely empty /wp-content folder and clone the repo like this:

git clone https://github.com/some/repo.git .

That extra dot at the end. That’s all it takes! But if you find yourself getting a Terminal error that the directory isn’t empty, make sure you check for hidden files, like the classic ol’ DS_Store.

If that approach won’t do, it just takes a couple more steps:

git init
git remote add origin https://github.com/some/repo.git 
git pull origin master

Either of those approaches will clone just the contents of the repo rather than packaging them up into a root directory.

(Updated on 12/31/2021)

3 Comments

  1. # August 25, 2020

    In reply to https://geoffgraham.wpengine.com/how-to-clone-just-the-contents-of-a-github-repository/.
    Uh, yeah, but no. That dot simply means “(clone into) the current directory.” Also, “savant”?

    • # August 26, 2020

      Huh! Seems to have worked for me based on the Stack Overflow answer I found. Also, based on the answer, I thought the dot also initializes git, no?

Comments are closed.