pygitmirror
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
- Three operations:
cloneonly adds,syncmakes the destination equal to the source,migrateclones, 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. 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, notlocalhost. - The page offers Gitea, Forgejo, GitLab and plain git servers for now; the command has all hosts.
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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pygitmirror-0.2.0.tar.gz | 186.6 kB | Without provenance | Details for pygitmirror-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pygitmirror-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for pygitmirror-0.2.0-py3-none-any.whl |
Total release size: 378.6 kB
Release files / pygitmirror-0.2.0.tar.gz
| Download URL | pygitmirror-0.2.0.tar.gz |
|---|---|
| Size | 186.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d158bb9a1d6d595799b1b5ae839ba64bf26911e080adf56f160d3dd3cccad4c
|
|
BLAKE2b-256 checksum How to use checksums |
6ece297d7b8a98bc4c243a9bcc5315b06ae1b378412b4a0f727a1ec602189374
|
| 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.0-py3-none-any.whl
| Download URL | pygitmirror-0.2.0-py3-none-any.whl |
|---|---|
| Size | 192.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
58197e96ba4795295fe234f1ebba394d2c7546db58ece200684993f9fa3cdb12
|
|
BLAKE2b-256 checksum How to use checksums |
4495478e80cacb2742a2d715e0b7675cf2e7e82177342969014c19b02e103598
|
| 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.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.