Using git filters to extract or separate FreeBSD components into their own git repos.

This is still a work in progress. Two examples will be provided.

git-filter-repo is a handy port that will rewrite git history, including separating FreeBSD components from the tree. Following is how I separated telnet (telnetd, libtelnet, and telnet) into its own repo.

  1. git clone a fresh copy of src.
  2. git filter-repo –path contrib/telnet –path lib/libtelnet –path libexec/telnetd –path usr.bin/telnet
  3. git reflog expire –all –expire-unreachable=0
  4. git repack -A -d
  5. git prune

This resulted in a 1 MB git repo containing only telnet.

git-filter-repo is recommended by the authors of git. git-filter-branch displays a message suggesting that git-filter-repo be used.

As efficient as git-filter-repo is, I discovered it deleted files that should not have been deleted when extracting ftpd into its own repo. The other tool at our disposal is git-filter-branch, which is already packaged with git. Though git warns about git-filter-branch caveats and the possibility of repo corruption, it was the only solution to separate ftpd into its own repo. The steps I used are:

  1. git clone a fresh copy of src.
  2. git filter-branch –subdirectory-filter libexec/ftpd
  3. git filter-branch –tag-name-filter cat –index-filter 'git rm -r –cached –ignore-unmatch filename' –prune-empty -f – –all
  4. rm -r .git/refs/original
  5. git reflog expire –expire=now –all
  6. git gc –prune=now
  7. git gc –aggressive

This resulted in a 448KB git repo only containing ftpd.

Hopefully this will be of use to someone. I will expound on the above at a later date as time permits.

  • git-filter.txt
  • Last modified: 2026/10/12 10:55
  • (external edit)