git-filter-branch

Extract a subdirectory's commit history using git-filter-branch and merge it into another repository.

3|1|Updated Apr 12, 2026
One-click install
npx skills add https://github.com/Cogni-AI-OU/cogni-ai-agent-skills --skill git-filter-branch
Or copy as Structured Prompt for Agentā–¼
Please help me install this Agent Skill.
Skill: git-filter-branch
Source: https://github.com/Cogni-AI-OU/cogni-ai-agent-skills/tree/main/git-filter-branch
Command: npx skills add https://github.com/Cogni-AI-OU/cogni-ai-agent-skills --skill git-filter-branch

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you migrate a specific subdirectory from one Git repository into another while preserving the original commit history for that subdirectory, even when newer tools like git-filter-repo are unavailable.

Core Features & Use Cases

  • Subdirectory history extraction: Rewrites history so only the chosen path becomes the root of the filtered repository.
  • History-preserving merge: Merges the isolated, rewritten commit graph into your target repository while allowing unrelated histories.
  • Safety guidance for common failures: Covers pitfalls such as root-file conflicts, long runtimes on large repos, and pre-commit hook issues.

Quick Start

Use the git-filter-branch skill to extract the folder you care about as a standalone history by running git filter-branch with the --subdirectory-filter option on the source repository, then merge the filtered remote into your main repository with --allow-unrelated-histories.

Frequently Asked Questions about git-filter-branch

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I extract a subdirectory from a git repository while preserving commit history?ā–¼

To extract a subdirectory while preserving commit history, clone the source repository and run git filter-branch with the --subdirectory-filter option to rewrite history so the target path becomes the repository root.

What is the best way to merge unrelated histories when migrating a subdirectory to a new repository?ā–¼

The best way to merge unrelated histories is to add the filtered clone as a remote in your target repository, then merge the default branch using the --allow-unrelated-histories flag to incorporate the isolated commits.

Can I use git filter-branch for mono-repo migrations if git filter-repo is unavailable?ā–¼

Yes, you can use git filter-branch for mono-repo migrations as a fallback when git filter-repo or subtree are missing or impractical, allowing you to partition repositories by rewriting and merging specific paths.

Why does subdirectory history extraction with git filter-branch result in root-file conflicts?ā–¼

Root-file conflicts occur during history extraction when existing files in the target repository clash with the rewritten root files brought in from the filtered subdirectory clone during the unrelated histories merge.

What are the limitations of using git filter-branch for repository partitioning?ā–¼

Limitations of using git filter-branch for repository partitioning include long runtimes on large repositories and potential pre-commit hook issues, requiring safety guidance to manage these common failures.