How do I checkout only one folder from my repository?

A Bitbucket subscriber writes:

I want to be able to pull only a specific file folder from the repo after
I have done a git init in a particular folder on my local machine.
I have several hundred folders from which I am interested in only one at a

time for a deployment.
However, I have not been able to come across any git command that enables
me to do so.

1 answer

1 accepted

This widget could not be displayed.

It's important to remember that every time you clone or checkout a repository, a full copy of (at least) the entire repository's state at the specified commit is delivered to your machine.

Considering that, you can do the following:

git clone <repo-url> --depth 1 --bare 
git --work-tree=/path/to/checkout checkout HEAD -- sub/directory

The first line will clone the full current state of your repository, omitting any history, without creating a work-folder.

The second line unpacks the folder desired.

We strongly recommend making any commits to the files in this state; it's much better to work on a full copy of a working directory.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

69 views 0 1
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you