GIT-CLONE-SUBSET(1)
π GIT-CLONE-SUBSET(1) π
okay bestie, welcome to git-clone-subset β it's a General Commands Manual page and it's about to be your new obsession. she clones a subset of a git repository. that's it, that's the whole vibe. β¨
πΈ NAME πΈ
git-clone-subset β Clones a subset of a git repository π
π¦ SYNOPSIS π¦
git-clone-subset [options] repository destination-dir pattern
π DESCRIPTION π
so here's the tea β β this girl clones a repository into a destination-dir, and then she prunes from history every single file except the ones matching pattern. how? by running this on the clone:
git filter-branch --prune-empty --tree-filter 'git rm ...' -- --all
which basically means you end up with a clone that has a subset of files (and history)</bad> of the original repo. and the original repository? not modified. not touched. not even looked at funny. π
she's lowkey perfect for making a brand-new repository out of a handful of files from another repository, and migrating (only) their associated history along with them. it's giving... very similar to:
git filter-branch --subdirectory-filter
but no cap, git-clone-subset works on a path pattern instead of just a single directory. that's the glow-up. periodt. π₯
β¨ OPTIONS β¨
-h,--helpβ show usage information. that's it, she's helpful, we love her π«Άrepositoryβ URL or local path to the git repository to be cloned. yes, either one, she doesn't discriminate πdestination-dirβ Directory to create the clone. Same rules forgit-cloneapplies: it will be created if it does not exist, and it must be empty otherwise. But β and this is the plot twist β unlikegit-clone, this argument is not optional. why? becausegit-cloneuses several rules to determine the "friendly" basename of a cloned repo, andgit-clone-subsetwill not risk parsing its output, let alone predict the chosen name. she's not doing that guesswork, bestie, she has boundaries. πpatternβ Glob pattern to match the desired files/dirs. It will ultimately be evaluated by a call to bash, NOT git or sh, using the extended glob'!(<pattern>)'rule. Quote it or escape it on the command line so it does not get evaluated prematurely by your current shell. Only a single pattern is allowed: if more are required, use extglob's"|"syntax. Globs will be evaluated with bash'sshopt dotglobset, so beware. π
Patterns should not contain spaces or special chars like"'$(){}`, not even quoted or escaped, since that might interfere with the!()syntax after pattern expansion. fr fr, don't do it.
Pattern Examples:
"*.png"
"*.png|*icon*"
"*.h|src/|lib"
π LIMITATIONS π
ngl, there are some things she just can't do, and we gotta be honest about them:
- Renames are NOT followed. As a workaround, list the rename history with:
git log --follow --name-status --format='%H' -- file | grep "^[RAD]"
and include all multiple names of a file in the pattern, as in "current_name|old_name|initial_name". As a side effect, if a different file has taken place of an old name, it will be preserved too, and there is no way around this using this tool. π
- There is no (easy) way to keep some files in a dir: using
'dir/foo*'as pattern will not work. So keep the whole dir and remove files afterwards, usinggit filter-branchand a (quite complex) combination of cloning, remote add, rebase, etc. it's giving effort, unfortunately. π - Pattern matching is quite limited, and many of bash's escaping and quoting does not work properly when
patternis expanded inside!(). she's doing her best okay π«Ά
π SEE ALSO π
π§ AUTHOR π§
Rodrigo Silva (MestreLion) linux@rodrigosilva.com
and that's the whole page, bestie!! this gorgeous little manual page was served up by the General Commands Manual crew and dated 2021-02-11 β go forth and clone your subsets, you absolute main character ππβ¨
π¦ where this page comes from
- debian bookworm: git-restore-mtime 2022.12-1 Β· GPL-3.0-or-later
- debian trixie: git-restore-mtime 2022.12-1 Β· GPL-3.0-or-later
- epel 10: git-tools 2025.08-1.el10_2 Β· GPL-3.0-or-later
- epel 9: git-tools 2025.08-1.el9 Β· GPL-3.0-or-later
- fedora 43: git-tools 2025.08-1.fc43 Β· GPL-3.0-or-later
- fedora 44: git-tools 2025.08-2.fc44 Β· GPL-3.0-or-later
- nixos 26.05: git-tools 2025.08
- nixpkgs unstable: git-tools 2025.08
- ubuntu noble: git-restore-mtime 2022.12-1 Β· GPL-3.0-or-later
- ubuntu questing: git-restore-mtime 2022.12-1
- ubuntu resolute: git-restore-mtime 2022.12-1build1 Β· GPL-3.0-or-later
- ubuntu stonking: git-restore-mtime 2022.12-1build1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms