Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check out only a subdirectory in Git?

Let’s say I have a repository MyRepo with this structure:

MyRepo/subDirLevel1/subDirLevel2/someFile

I’m only interested in subDirLevel2. I know with sparse checkout I could do e.g. this:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

git clone --filter=blob:none --no-checkout --depth 1 --sparse link/to/MyRepo.git
cd MyRepo
git sparse-checkout add subDirLevel1/subDirLevel2
git checkout

which would check out only the subDirLevel2‘s contents without any other stuff that might possibly be in subDirLevel1 or MyRepo.

But I would like to "skip" the subDirLevel1 dir altogether so that after the checkout I would end up with either:

C:\projects\MyRepo\subDirLevel2

or possibly:

C:\projects\subDirLevel2

with it still being a repo I can run commands (e.g. git status) on.

Is this possible? (I don’t need to be able to commit to that repo, if that changes anything, just git pull to keep it up-to-date.)

>Solution :

No, and I doubt it will ever be implemented. Sparse checkout is implemented using "skip worktree" flags for not checked out paths but paths in the working tree must correspond to trees in commits/index.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading