Path Renaming Options
Path renaming options allow you to restructure your repository by renaming or moving files and directories throughout history.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
:) with nothing after it means “move to root”.
Moving from Root
:) with nothing before it means “apply to root”.
Multiple Renames
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:Move Project to Subdirectory
Using shortcut:The long form requires understanding that
: means root level.Merge Two Directories
api/.
Reorganize Directory Structure
Rename and Filter
Advanced Renaming
Conditional Renaming with Callbacks
For complex renaming logic, use--filename-callback:
Regex-Based Renaming
Use--paths-from-file with regex for pattern-based renaming:
Create paths.txt:
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
Rename Processing Order
Renames are applied in the order specified: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
- Path Options → - Path filtering
- CLI Overview → - All command options
- Examples → - Restructuring examples
