Skip to main content

pygitmirror

Tests Documentation PyPI version Python versions Weekly downloads Monthly downloads Total downloads Docker image License

Clone, sync and migrate git repositories between GitHub, GitLab, Gitea, Bitbucket and any other git server. A command, git-mirror, a page which runs on your own machine, 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

The source is fetched into a local mirror, which is pushed to the destination

  • 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
  • Runs locally: your machine, your tokens; nothing is sent anywhere but to the two servers
  • 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.

The page

git-mirror serve

prints a link to a page on your own machine: choose two servers, list the repositories, preview, and run.

The page: a headline, and commits traveling from the source through the local mirror to the destination

The results of a preview: figures of what would be created, updated and deleted, and one row per repository

Or with Docker:

docker run -d --name git-mirror \
    -p 127.0.0.1:47417:47417 \
    -v git-mirror-data:/data \
    --add-host host.docker.internal:host-gateway \
    ghcr.io/pygitmirror/pygitmirror

docker logs git-mirror    # shows the link to open
  • A repository passes through a copy on your machine, so the volume needs room for the largest repository, or for all of them if the copies are kept to make the next sync fast.
  • Inside the container, a server on your machine is host.docker.internal, not localhost.
  • The page offers Gitea, Forgejo, GitLab and plain git servers for now; the command has all hosts.

See the guide to the page.

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.2.1

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.2.1
File Size Uploaded Provenance Actions
pygitmirror-0.2.1.tar.gz 190.7 kB Without provenance Details for pygitmirror-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 385.4 kB

Release files / pygitmirror-0.2.1.tar.gz

Download URL pygitmirror-0.2.1.tar.gz
Size 190.7 kB
Tags Source
SHA-256 checksum
How to use checksums
926917bba330d6ec5cde524cf3139a7130f195d103716291ab6081cbd280fee8
BLAKE2b-256 checksum
How to use checksums
3b4c17261a794fdb7a53ace72cb5c2facd566ed6197dc766bab10528e2d787c8
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.2.1-py3-none-any.whl

Download URL pygitmirror-0.2.1-py3-none-any.whl
Size 194.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fe0cf4ebd55d004376a40cb86ea664a3ab685dc60b46a92340cc3784dcfd6da1
BLAKE2b-256 checksum
How to use checksums
4bdc87751f59de40b738502c2610f348bc49d843dc1c723253149db936e7de03
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.2.1

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