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 an Terminal error that the directory isn’t empty, make sure you check for hidden files, like the classic ol’
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.