Skip to main content

pygitmirror

Tests Documentation PyPI version Python versions License

Clone, sync and migrate git repositories between GitHub, GitLab, Gitea, Bitbucket and any other git server. A command, git-mirror, and a Python library.

export GIT_MIRROR_SOURCE_TOKEN=...       # a GitHub token
export GIT_MIRROR_DESTINATION_TOKEN=...  # a Gitea token

git-mirror sync --source github \
    --destination gitea --destination-url https://git.example.com \
    --org my-org --all
  • Three operations: clone only adds, sync makes the destination equal to the source, migrate clones, verifies and can archive the source
  • Creates what is missing: destination repositories are created with the description and visibility of the source
  • All branches and tags, for one repository or every repository of an organization
  • Cheap to repeat: a repository which did not change costs two short requests and no download
  • Careful with tokens: read from the environment, never written to a file, a URL or a command line
  • No dependencies: needs Python 3.11 and git 2.31, nothing else
  • Typed: type hints throughout, checked with mypy in strict mode

Full documentation: https://pygitmirror.readthedocs.io/

Installation

pip install pygitmirror

Operations

clone sync migrate
adds missing branches and tags yes yes yes
moves a branch forward yes yes yes
overwrites a branch or tag which differs no, fails yes no, fails
deletes what the source does not have no yes no, fails
checks the destination afterwards no no yes
can archive the source no no yes

Add --dry-run to any of them to see what would be done.

# A first copy which cannot overwrite anything
git-mirror clone --source github --destination gitlab --org my-org --repo api web

# Keep a copy up to date, for example from cron
git-mirror sync --source github --destination gitlab --org my-org --all

# Move to a new home and make the old one read-only
git-mirror migrate --source bitbucket --destination github \
    --org my-workspace --destination-org my-org --all

Only branches and tags are copied: not issues, pull requests, wikis, releases or Git LFS files.

Hosts

Provider Servers Creates repositories
github github.com, GitHub Enterprise Server yes
gitlab gitlab.com, self-managed GitLab yes
gitea Gitea, Forgejo yes
bitbucket bitbucket.org yes
plain any git server or local folder no, the destination must exist

Without --source or --destination a host is plain, and the URL of a repository is the address followed by the owner and the name:

git-mirror clone --source-url ssh://git@old.example.com:7999 \
    --destination-url https://git.example.com --org my-project --repo api

Settings file

To name many repositories at once, use a JSON file, in which lines starting with // are comments:

{
  "sync_path": "/var/lib/git-mirror",
  "source": { "provider": "github" },
  "destination": { "provider": "gitea", "url": "https://git.example.com" },
  "repos": {
    // These two only.
    "organization-1": ["repo-1", "repo-2"],
    // Every repository of the organization.
    "organization-2": "*"
  }
}
git-mirror sync --config settings.json

Python

from pygitmirror import Mirror, make_host

source = make_host("github", token=github_token)
destination = make_host("gitea", url="https://git.example.com", token=gitea_token)

mirror = Mirror(source, destination, workdir="/var/lib/git-mirror")
result = mirror.sync("my-org/api")
print(result.summary())

Upgrading from 0.0

Calls such as git-mirror --source_url ... --destination_url ... --org ... --repo ... and the settings files of the first versions still work; they run clone. The changelog lists what changed.

Development

git clone https://github.com/pygitmirror/pygitmirror.git
cd pygitmirror
make install  # create the environment with uv
make check    # lint, type check, test and build the docs

See CONTRIBUTING.md.

License

MIT. Maintained by Bassem Girgis.

Metadata

Release files for pygitmirror 0.1.0

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

Source distribution (sdist)

Source distribution for pygitmirror 0.1.0
File Size Uploaded Provenance Actions
pygitmirror-0.1.0.tar.gz 41.9 kB Without provenance Details for pygitmirror-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pygitmirror 0.1.0
File Interpreter ABI Platform Actions
pygitmirror-0.1.0-py3-none-any.whl Python 3 none any Details for pygitmirror-0.1.0-py3-none-any.whl

Total release size: 86.0 kB

Release files / pygitmirror-0.1.0.tar.gz

Download URL pygitmirror-0.1.0.tar.gz
Size 41.9 kB
Tags Source
SHA-256 checksum
How to use checksums
86de6c9384ba7a27925299d4cc0d7c6621811e27eb19fc361e1cbdfdd5fc6416
BLAKE2b-256 checksum
How to use checksums
13928e6075f306d5302588b7124d7d41e852a98cfd8b4c80a4a6727b4fede1ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / pygitmirror-0.1.0-py3-none-any.whl

Download URL pygitmirror-0.1.0-py3-none-any.whl
Size 44.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
669f3409cf6c96d06a03fd8d197676a013a806124e7b7094d18e0afdb44c9613
BLAKE2b-256 checksum
How to use checksums
17bf47db438e49aba1114b2f5ac1e322b47ba1015c94e2f993107357973944e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.10 {"installer":{"name":"uv","version":"0.13.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for pygitmirror 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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