Don't think of a Git repo as a collection of files, but a collection of snapshots. Git doesn't allow you to select what files you download, but allows you to select how many snapshots you download:
git clone [email protected]:/home2/git/stack.git
will download all snapshots for all files, while
git clone --depth 1 [email protected]:/home2/git/stack.git
will only download the latest snapshot of all files. You will still download all files, but at least leave out all of their history.
Of these files you can simply select the one you want, and delete the rest:
import os
import git
import shutil
import tempfile
# Create temporary dir
t = tempfile.mkdtemp()
# Clone into temporary dir
git.Repo.clone_from('[email protected]:/home2/git/stack.git', t, branch='master', depth=1)
# Copy desired file from temporary dir
shutil.move(os.path.join(t, 'setup.py'), '.')
# Remove temporary dir
shutil.rmtree(t)
git archive --remote
. – Cutlery