that command above copies content of entire repo to another directory
In git terminology, what it's doing is checking out a commit. To check out just part of a commit you have to tell it to read out just some of the committed tree.
As a side note, git's not built to be a deployment server. That said, it's simple and flexible enough that using it as you want here is fairly popular and works pretty well.
Git maintains an index file that relates what's in the work tree to what's in the repo. So if you want to use git to manage what's in an arbitrary worktree, you have to keep an index file for that worktree.
(
# git ordinarily finds these for itself, but we're not using default behavior:
export GIT_DIR=/var/repo/site.git
export GIT_INDEX_FILE=$GIT_DIR/domain.com.index
export GIT_WORK_TREE=/var/www/domain.com
git read-tree -um `git write-tree` HEAD:dist # or master:dist, or any tree reference
)
The git write-tree
gets you the tree for whatever content is currently listed in the index (an empty or nonexistent file works just fine as a "nothing's here yet" index). git read-tree -um
with two trees is what underlies checkout, it doesn't care about refs at all, not even HEAD; it's concerned solely with trees and the index.