Skip to main content

Overview

Path-based filtering allows you to rename files and directories throughout your repository’s entire history. This is essential when restructuring projects, merging repositories, or correcting naming conventions.

Path Renaming Basics

Simple Rename

Rename a directory throughout history:
Trailing slashes are optional for directories:
  • tools/:scripts/ (with slash)
  • tools:scripts (without slash)
Both work identically.

Multiple Renames

Perform several renames in one operation:
Order Matters!Renames are applied in the order specified. The command above:
  1. First renames cmds → tools
  2. Then renames src/scripts/ → tools/
Reversing the order could give different results.

Advanced Renaming

Merge Directories

Rename multiple directories to the same location:

Handle Naming Conflicts

If two files would collide when renamed, specify an additional rename:
Specific file renames should come before directory renames to prevent conflicts.

Combining Filtering and Renaming

Filter Then Rename

Path renaming doesn’t filter paths - combine with --path for that:

Create New Structure

Restructure your repository layout:
Order is critical! The command above:
  1. First renames sources/ → src/main/
  2. Then filters to keep only src/main/
Reversing these steps would result in an empty repository.

Restructuring Projects

Flatten Directory Structure

Move files from nested directories to root:

Create Nested Structure

Add directory layers:
Empty string before : means repository root.

Module Reorganization

Reorganize a monorepo into separate modules:

Merging Repositories

Prepare Repository for Merge

When merging multiple repositories, prefix each with a unique directory:
Result:

Split Monorepo

Extract a module and rename it:

Regex-Based Renaming

Use regex for complex renaming patterns:
Regex Syntax:
  • (.*) - Capture group (any characters)
  • [^/]* - Non-slash characters
  • \1, \2, \3 - Back-references to captured groups
See Python regex syntax for details.

Complex Renaming Examples

Normalize File Extensions

Add Version Prefix to Directories

Reorganize by Language

Group files by programming language:

Renaming with Callbacks

For extremely complex renames, use Python callbacks:
See Advanced Filtering for more on callbacks.

Important Considerations

Collision DetectionIf renames cause two different files to have the same path, filter-repo will error:
Resolve by renaming one of the conflicting files first.
Silent OverwritesIf you rename a path to one that already exists, the existing file is silently overwritten. Use --analyze to check for potential conflicts first.
Test FirstUse --dry-run to preview changes:
This shows what would happen without modifying the repository.

Partial Renames

Rename paths only on specific branches:
This uses --partial mode, which mixes old and new history. Use carefully!

Verification

After renaming, verify the results:

Next Steps