Skip to main content

A CLI tool to rewrite Git commit authors and committers

Project description

GitAuth

A powerful, production-grade CLI tool to safely rewrite Git commit authors and committers across your repository history.

Features

  • ๐Ÿ”„ Flexible Rewriting: Change specific authors or rewrite all commits
  • ๐Ÿ” Author Detection: Identify all unique authors in your repository
  • ๐Ÿงช Dry Run Mode: Preview changes before applying them
  • ๐Ÿ’พ Automatic Backups: Create repository backups before rewriting
  • โšก Two Backends: Uses git filter-repo (preferred) with git filter-branch fallback
  • ๐Ÿ›ก๏ธ Safety First: Validates repo state and provides clear warnings
  • ๐Ÿ“ Preserves History: Keeps commit messages, timestamps, and commit order intact
  • ๐ŸŒ Cross-Platform: Works on macOS, Linux, and Windows

Installation

From PyPI

pip install gitauth

From Source

git clone https://github.com/mubashardev/gitauth.git
cd gitauth
pip install -e .

Optional: Install git-filter-repo

For best performance, install git-filter-repo:

# macOS
brew install git-filter-repo

# Linux (Debian/Ubuntu)
sudo apt-get install git-filter-repo

# Or via pip
pip install git-filter-repo

If not installed, gitauth will automatically fall back to git filter-branch.

Usage

Check Repository Authors

List all unique authors in your repository:

gitauth check

Output:

Found 3 unique authors:
  John Doe <john@example.com>
  Jane Smith <jane@example.com>
  Old Name <old@dev.com>

Dry Run (Preview Changes)

See which commits would be changed without modifying anything:

# Preview changes for a specific email
gitauth dry-run --old-email "old@dev.com"

# Preview changes for a specific name
gitauth dry-run --old-name "Old Name"

Rewrite Specific Author

Change commits from a specific author:

# By email
gitauth rewrite --old-email "old@dev.com" --new-name "New Name" --new-email "new@dev.com"

# By name
gitauth rewrite --old-name "Old Name" --new-name "New Name" --new-email "new@dev.com"

# Both (more specific)
gitauth rewrite --old-email "old@dev.com" --old-name "Old Name" --new-name "New Name" --new-email "new@dev.com"

Rewrite All Commits

Change all commits to a new author:

gitauth rewrite --all --new-name "New Name" --new-email "new@dev.com"

Create Backup

Manually create a backup of your repository:

gitauth backup

Creates: backup-YYYYMMDD-HHMMSS.tar.gz

Push Changes

After rewriting, push to remote (use with caution!):

# Interactive confirmation
gitauth push

# Force push without confirmation
gitauth push --force

Enable Verbose Logging

Add --verbose to any command for detailed output:

gitauth rewrite --old-email "old@dev.com" --new-name "New Name" --new-email "new@dev.com" --verbose

Branch-Specific Operations

Filter operations by specific branch:

# Check authors only on main branch
gitauth check --branch main

# Preview commits from specific branch
gitauth dry-run --old-email "old@dev.com" --branch develop

# Interactive selection for a specific branch
gitauth dry-run --choose-old --branch feature/new-feature

Note: The --branch option filters which commits are analyzed and displayed. When using the rewrite command, git-filter-repo and git-filter-branch rewrite history across all branches by default (this is standard Git behavior for history rewriting tools).

โš ๏ธ Important Warnings

History Rewriting

Rewriting Git history is a destructive operation. Before using this tool:

  1. โœ… Always create a backup (or work on a clone)
  2. โœ… Coordinate with your team if working on a shared repository
  3. โœ… Understand the implications of force-pushing
  4. โœ… Test on a branch first before affecting main/master

Force Pushing

After rewriting history, you'll need to force push:

git push --force-with-lease origin main
# or use: gitauth push --force

Warning: This will rewrite history on the remote. All collaborators must re-clone or reset their local repositories.

Examples

Example 1: Fix Personal Email

You accidentally committed with your work email and want to change it to personal:

# 1. Check current authors
gitauth check

# 2. Preview changes
gitauth dry-run --old-email "work@company.com"

# 3. Rewrite commits
gitauth rewrite --old-email "work@company.com" --new-name "Your Name" --new-email "personal@gmail.com"

# 4. Push changes
gitauth push

Example 2: Unify Multiple Identities

You committed with different names/emails and want to unify them:

# Fix first identity
gitauth rewrite --old-email "old1@example.com" --new-name "Your Name" --new-email "unified@example.com"

# Fix second identity
gitauth rewrite --old-email "old2@example.com" --new-name "Your Name" --new-email "unified@example.com"

# Push once
gitauth push

Example 3: Transfer Repository Ownership

Change all commits to a new author (e.g., transferring project ownership):

# Preview all commits
gitauth dry-run --all

# Rewrite all
gitauth rewrite --all --new-name "New Owner" --new-email "newowner@example.com"

# Push
gitauth push

How It Works

  1. Detection: Scans repository using git log to find commits matching criteria
  2. Validation: Checks if repository is clean and valid
  3. Backup: Optionally creates a compressed backup
  4. Rewriting: Uses git filter-repo (fast) or git filter-branch (fallback)
  5. Preservation: Maintains commit timestamps, messages, and tree structure
  6. Safety: Provides dry-run mode and interactive confirmations

Project Structure

gitauth/
โ”œโ”€โ”€ gitauth/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ cli.py              # Typer CLI interface
โ”‚   โ””โ”€โ”€ core/
โ”‚       โ”œโ”€โ”€ __init__.py
โ”‚       โ”œโ”€โ”€ git_utils.py    # Git operations and validation
โ”‚       โ”œโ”€โ”€ detect.py       # Author detection
โ”‚       โ”œโ”€โ”€ backup.py       # Backup functionality
โ”‚       โ””โ”€โ”€ rewrite.py      # Rewrite logic (filter-repo/filter-branch)
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ”œโ”€โ”€ test_git_utils.py
โ”‚   โ”œโ”€โ”€ test_detect.py
โ”‚   โ”œโ”€โ”€ test_backup.py
โ”‚   โ””โ”€โ”€ test_rewrite.py
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ LICENSE

Development

Setup Development Environment

git clone https://github.com/yourusername/gitauth.git
cd gitauth
pip install -e ".[dev]"

Run Tests

pytest
pytest --cov=gitauth tests/

Format Code

black gitauth tests
ruff check gitauth tests

Build Package

python -m build

Publish to PyPI

python -m twine upload dist/*

Requirements

  • Python 3.8+
  • Git 2.0+
  • git-filter-repo (optional, recommended)

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Ensure all tests pass
  5. Submit a pull request

Changelog

Version 1.0.0

  • Initial release
  • Support for git filter-repo and git filter-branch
  • Dry run mode
  • Automatic backups
  • Author detection
  • Cross-platform support

Support

Acknowledgments


Made with โค๏ธ by Mubashar Dev

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gitauth-1.1.0.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gitauth-1.1.0-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

File details

Details for the file gitauth-1.1.0.tar.gz.

File metadata

  • Download URL: gitauth-1.1.0.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for gitauth-1.1.0.tar.gz
Algorithm Hash digest
SHA256 2de89340ac11f22adacc5344ffa01056b0333661306c036b5a84eedd8b04b735
MD5 14ce0419fde41a076f6c52d7ac576523
BLAKE2b-256 a46a5bb0d799a29af6a6b0f6ccbd39ff82f34d04f4f82b2ca5ae6bbbc865341a

See more details on using hashes here.

File details

Details for the file gitauth-1.1.0-py3-none-any.whl.

File metadata

  • Download URL: gitauth-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 19.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.9

File hashes

Hashes for gitauth-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4efe6d06b9289f6d8b3f83d9475a01e7e494a419a67f92f0b38098cef11f18f5
MD5 316ec8880393938d821f7859637211b6
BLAKE2b-256 12c076146df9511028b443cc1f5e10cda56708cd9813fd0bd3e16b5805924727

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page