This tool is used to split parts of a repository into a new repository. The tool must be executed inside the source repository, but does not modify the source repository (make sure to read the disclaimer). The tool tries to determine file renames and keep history across renames accordingly.
The script prefers git filter-repo (the modern, officially recommended
replacement for git filter-branch) and falls back to git filter-branch
if git filter-repo is not available.
# via pip
pip install git-filter-repo
# via Homebrew (macOS)
brew install git-filter-repo
# via package manager (Debian/Ubuntu)
sudo apt install git-filter-repoSee https://github.com/newren/git-filter-repo for more installation options.
git filter-branch is still supported as a fallback. It has been deprecated
since Git 2.24 but remains functional. The script suppresses the deprecation
warning automatically via FILTER_BRANCH_SQUELCH_WARNING=1.
usage: gitsplit branch dst [keep [keep ...]]
DESCRIPTION
This tool is used to split parts of a repository into a new
repository. The tool must be executed inside the source re-
pository. The specified destination path cannot be a sub-
directory of the source repository.
ARGUMENTS
branch The source branch to split from.
dst The destination path for the repository to create.
This path must not exist.
keep One path or multiple paths to keep in the new repository.
If no paths are specified the entire source branch is
split into a new repository.
# Split the 'src/mymodule' directory and a single file from 'main' branch
# into a new repository at '../new-repo'
cd /path/to/source-repo
gitsplit main ../new-repo src/mymodule README.mdgit filter-reposupport: The script now usesgit filter-repoas the primary filter tool when available. This is the officially recommended replacement forgit filter-branchand is significantly faster and more reliable, especially for large repositories.git filter-branchfallback: Whengit filter-repois not installed, the script falls back togit filter-branchwithFILTER_BRANCH_SQUELCH_WARNING=1to suppress the deprecation warning that would otherwise interfere with the script.- Fixed
xargsempty-input bug:git remote | xargs git remote rmandgit tag -l | xargs git tag -dwould fail when there were no remotes or tags. These are now handled with explicit loops. - Fixed rename-tracking: The previous
git log --follow --name-status --onelineapproach mixed commit-message lines with file-status lines, causing incorrect array indexing. The new approach uses--diff-filter=R --format=""to emit only rename lines, parsed correctly with tab-separated fields. - Iterative rename chain following: Renames are now followed transitively (A→B→C), so the full rename history is preserved.
- Safer path handling: Paths are normalized without a Perl dependency. Destination path resolution no longer fails when the parent directory does not yet exist.
- Branch existence check: The script now verifies that the specified branch exists before proceeding.
set -euo pipefail: The script now exits immediately on errors, unbound variables, or pipe failures.- Automatic cleanup: A
traphandler ensures the temporary directory is always removed, even if the script is interrupted. --no-localclone flag: Ensures a proper clone (with full object copying) rather than a hardlink-based local clone, which is important for subsequentfilter-repo/filter-branchoperations.
Use with caution. This software may contain serious bugs. I can not be made responsible for any damage the software may cause to your system or files. Make sure to backup your source repository before using this tool.
gitsplit
Copyright (C) 2018-present by Harald Lapp harald@octris.org
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.