Skip to main content

Path Renaming Options

Path renaming options allow you to restructure your repository by renaming or moving files and directories throughout history.
Path renaming does NOT select paths - it only renames paths that are selected by filter options. You need both filter AND rename options for most use cases.

Basic Path Renaming

—path-rename

string
Rename paths matching OLD_NAME to NEW_NAME.Format: OLD_NAME:NEW_NAMEAliases: --path-rename-matchMultiple: Yes - can be specified multiple timesApplies to: Both files and directoriesTrailing slashes: Optional for directoriesBasic examples:

Rename Patterns

Moving to Root

The colon (:) with nothing after it means “move to root”.

Moving from Root

The colon (:) with nothing before it means “apply to root”.

Multiple Renames

Both cmds/ and src/scripts/ are renamed to tools/.

Handling Collisions

If renaming causes path collisions, rename one first:

Common Use Cases

Extract Subdirectory as Project Root

Using shortcut:
Equivalent long form:

Move Project to Subdirectory

Using shortcut:
Equivalent long form:
The long form requires understanding that : means root level.

Merge Two Directories

Both directories are merged into api/.

Reorganize Directory Structure

Rename and Filter

Order matters! Filters must select paths in their FINAL names after renames:

Advanced Renaming

Conditional Renaming with Callbacks

For complex renaming logic, use --filename-callback:
Learn more about callbacks →

Regex-Based Renaming

Use --paths-from-file with regex for pattern-based renaming: Create paths.txt:
Apply renames:

Handling Special Cases

Renamed Files in History

If a file was renamed during repository history:

Case-Only Renames

On case-insensitive filesystems (Windows, macOS), you may need to use a temporary intermediate name.

Wildcard Alternatives

Since --path-rename doesn’t support wildcards directly, use --filename-callback:

Important Considerations

Path Filtering vs Path Renaming

Path renaming does NOT filter!This is empty (no paths selected):
This works (paths explicitly selected):

Rename Processing Order

Renames are applied in the order specified:
The result is sources/ → final/

Incompatibility with —use-base-name

--use-base-name and --path-rename cannot be used together.

Verification

After renaming, verify the results:

See Also