1GIT-CLONE-SUBSET(1) General Commands Manual GIT-CLONE-SUBSET(1)
2
3
4
6 git-clone-subset - Clones a subset of a git repository
7
9 git-clone-subset [options] repository destination-dir pattern
10
12 Clones a repository into a destination-dir and prune from history all
13 files except the ones matching pattern by running on the clone:
14 git filter-branch --prune-empty --tree-filter 'git rm ...' -- --all
15 This effectively creates a clone with a subset of files (and history)
16 of the original repository. The original repository is not modified.
17
18 Useful for creating a new repository out of a set of files from another
19 repository, migrating (only) their associated history. Very similar to:
20 git filter-branch --subdirectory-filter
21 But git-clone-subset works on a path pattern instead of just a single
22 directory.
23
25 -h, --help
26 show usage information.
27
28 repository
29 URL or local path to the git repository to be cloned.
30
31 destination-dir
32 Directory to create the clone. Same rules for git-clone
33 applies: it will be created if it does not exist and it must be
34 empty otherwise. But, unlike git-clone, this argument is not
35 optional: git-clone uses several rules to determine the
36 "friendly" basename of a cloned repo, and git-clone-subset will
37 not risk parse its output, let alone predict the chosen name.
38
39 pattern Glob pattern to match the desired files/dirs. It will be
40 ultimately evaluated by a call to bash, NOT git or sh, using
41 extended glob '!(<pattern>)' rule. Quote it or escape it on
42 command line, so it does not get evaluated prematurely by your
43 current shell. Only a single pattern is allowed: if more are
44 required, use extglob's "|" syntax. Globs will be evaluated
45 with bash's shopt dotglob set, so beware. Patterns should not
46 contain spaces or special chars like " ' $ ( ) { } `, not even
47 quoted or escaped, since that might interfere with the !()
48 syntax after pattern expansion.
49
50 Pattern Examples:
51
52 "*.png"
53 "*.png|*icon*"
54 "*.h|src/|lib"
55
57 Renames are NOT followed. As a workaround, list the rename history with
58 'git log --follow --name-status --format='%H' -- file | grep "^[RAD]"'
59 and include all multiple names of a file in the pattern, as in
60 "current_name|old_name|initial_name". As a side effect, if a different
61 file has taken place of an old name, it will be preserved too, and
62 there is no way around this using this tool.
63
64 There is no (easy) way to keep some files in a dir: using 'dir/foo*' as
65 pattern will not work. So keep the whole dir and remove files
66 afterwards, using git filter-branch and a (quite complex) combination
67 of cloning, remote add, rebase, etc.
68
69 Pattern matching is quite limited, and many of bash's escaping and
70 quoting does not work properly when pattern is expanded inside !().
71
73 https://github.com/MestreLion/git-tools
74
76 Rodrigo Silva (MestreLion) linux@rodrigosilva.com
77
78
79
80 2021-02-11 GIT-CLONE-SUBSET(1)