Skip to main content

git-rewrite

Git history rewriting tools - sanitise, flatten submodules, and remap references.

Installation

uv sync

Usage

Scan for Sensitive Words

Scan a repository for dirty words without making any changes:

uv run git-rewrite scan -r /path/to/repo -c config.json

Options:

  • -r, --repo - Path to the git repository
  • -c, --config - Path to JSON config file
  • -v, --verbose - Show verbose output

Sanitise Repository

Rewrite history to remove sensitive words:

uv run git-rewrite sanitise -r /path/to/repo -o /path/to/output -c config.json

Options:

  • -r, --repo - Path to source repository
  • -o, --output - Path for output repository
  • -c, --config - Path to JSON config file
  • -d, --default - Default replacement word (default: placeholder)
  • -m, --commit-map - Path to write commit mapping file
  • -s, --submodule-map - Path to submodule commit mapping file
  • --delete - Delete output directory if exists
  • --sample-config - Print sample config and exit
  • -v, --verbose - Show verbose output

Sample Configuration

{
    "words": ["secretword", "internalname", "sensitiveid"],
    "word_mapping": {
        "secretword": "publicword",
        "internalname": "externalname"
    },
    "email_mapping": {
        "john smith": "jsmith@example.com",
        "jane doe": "jdoe@example.com"
    },
    "exclude_files": [
        "package-lock.json",
        "yarn.lock"
    ]
}

Flatten Submodules

Flatten submodules into the main repository:

# Scan for submodules only
uv run git-rewrite flatten -r /path/to/repo --scan-only

# Flatten submodules
uv run git-rewrite flatten -r /path/to/repo -o /path/to/output

Options:

  • -r, --repo - Path to source repository
  • -o, --output - Path for output repository
  • -m, --commit-map - Path to write commit mapping file
  • --scan-only - Only scan and list submodules
  • --delete - Delete output directory if exists
  • -v, --verbose - Show verbose output

Remap Submodule References

Update submodule commit references in a repository:

uv run git-rewrite remap -r /path/to/repo -o /path/to/output -m mapping.txt

Options:

  • -r, --repo - Path to source repository
  • -o, --output - Path for output repository
  • -m, --commit-map - Path to commit mapping file
  • --submodule-path - Specific submodule path to remap
  • --url-rewrite OLD NEW - Rewrite URL in .gitmodules (can repeat)
  • --delete - Delete output directory if exists
  • -v, --verbose - Show verbose output

Workflow Example

A typical workflow for cleaning up and flattening a repository:

# 1. Scan for sensitive words
uv run git-rewrite scan -r ./myrepo -c dirty-words.json

# 2. Sanitise the repository
uv run git-rewrite sanitise -r ./myrepo -o ./myrepo-clean -c dirty-words.json \
    -m commit-map.txt

# 3. Flatten submodules in the cleaned repo
uv run git-rewrite flatten -r ./myrepo-clean -o ./myrepo-flat -m submodule-map.txt

# 4. Update consumer repositories to use new submodule commits
uv run git-rewrite remap -r ./consumer-repo -o ./consumer-updated \
    -m submodule-map.txt --submodule-path libs/mylib

Development

# Set up development environment
make dev

# Run linting and type checking
make check

# Auto-format code
make format

# Build wheel and docs
make build

Publishing

Publishing requires cal-publish-python configuration. See the cal-publish-python documentation for setup.

# Build first
make build

# Publish wheel to PyPI and docs to GitLab Pages
make publish

Requirements

  • Python 3.12+
  • Git

Licence

MIT

Metadata

Release files for git-rewrite 1.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for git-rewrite 1.2.0
File Interpreter ABI Platform
git_rewrite-1.2.0-py3-none-any.whl Python 3 none any Details

Release files / git_rewrite-1.2.0-py3-none-any.whl

Download URL git_rewrite-1.2.0-py3-none-any.whl
Size 59.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c21a32ad7e1d8825b78e412eb745403480ded59c8b6654e34a55f5f756a7dfd2
BLAKE2b-256 checksum
How to use checksums
23cd8ca85fe7cc6cdbaf794824f1c7cb40e2f789f64e69e49bde99d51ffca26e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.2

Release history Release notifications | RSS feed

This release

1.2.0 This release

1 release file

1.1.0

1 release file

1.0.1

1 release file

1.0.0

1 release file

0.13.2

1 release file

0.13.1

1 release file

0.13.0

1 release file

0.12.1

1 release file

0.12.0

1 release file

0.11.0

1 release file

0.10.0

1 release file

0.9.6

1 release file

0.9.1

1 release file

0.9.0

1 release file

0.8.1

1 release file

0.8.0

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.0

1 release file

0.4.2

1 release file

0.4.1

1 release file

0.4.0

1 release file

0.3.0

1 release file

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page