Jakub already mentioned a shallow clone of selected branches is possible, but quite complex to do.
And he added:
Note however that because branches usually share most of their history, the gain from cloning only a subset of branches might be smaller than you think.
I would add that you shouldn't have any VCS tool in a production plateform (you only install/monitor what is necessary for the production to run).
So git archive
remains the best way to extract just what you need, as an archive (zip
or tar
, format that you can then uses without Git, once transferred on the production side)
Update March 2012:
the upcoming git1.7.10 (April 2012) will actually allow you to clone only one branch:
git clone --single-branch
You can see it in t5500-fetch-pack.sh
:
test_expect_success 'single branch clone' '
git clone --single-branch "file://$(pwd)/." singlebranch
'
That feature was then fixes with:
clone --single
: limit the fetch refspec to fetched branch
After running "git clone --single
", the resulting repository has the usual default "+refs/heads/*:refs/remotes/origin/*
" wildcard fetch refspec installed, which means that a subsequent "git fetch
" will end up grabbing all the other branches.
Update the fetch refspec to cover only the singly cloned ref instead to correct this.
builtin/clone.c: detect a clone starting at a tag correctly
31b808a (clone --single
: limit the fetch refspec to fetched branch, 2012-09-20) tried to see if the given "branch" to follow is actually a tag at the remote repository by checking with "refs/tags/
" but it incorrectly used strstr(3)
; it is actively wrong to treat a "branch" "refs/heads/refs/tags/foo
" and use the logic for the "refs/tags/
"
ref hierarchy.
What the code really wanted to do is to see if it starts with "refs/tags/
".
Update Sept 2016: git clone --single-branch --branch tag
will work for chained tags in Git 2.11+ (Q4 2016).