Wednesday, 7 August 2013

git: Make the work tree reflect only a subpath of the whole tree

git: Make the work tree reflect only a subpath of the whole tree

I would like to checkout a whole branch, but work only inside a specific
directory of that branch. Therefore I would like to sort of "dive in" the
whole tree and make my work tree reflect only the subdirectory that I
chose. E.g.:
"master" tree
dir1/
file1
file2
dir2/
file3
work-dir tree
.git
file1
file2
My guess would be to do it like this:
git checkout master:dir1/
However, that doesn't work and reports the error:
fatal: Cannot switch branch to a non-commit 'master:dir1/'
Is this possible?
Note: I don't want to use submodules because I don't want to slice my repo
into unrelated pieces. Subtree merge, as far as I can tell, only helps me
to synchronize two separate directories with similar structures but
different histories. I want to modify the original objects in the repo and
be able to merge them back and forth and retain all the history.

No comments:

Post a Comment