Filter a repository history for mirroring to an untrusted forge.
Want to make your projects discoverable on centralised forges, but don't want to support the centralisation? Use this action to mirror only a readme and license file, so that interested users can find your repository on a centralised site, but have to leave it to use your code.
This action filters a local repository using git-filter-repo and writes the result to a target directory.
This example assumes the same user/repo on Codeberg/Forgejo as on GitHub.
on:
push:
branches:
- main
jobs:
mirror:
runs-on: codeberg-tiny-lazy
steps:
- name: Check out the source repository
uses: actions/checkout@v6
with:
fetch-depth: 0 # fetch all commits; we need history to rewrite it
- name: Check out the target repository
run: |
git clone github.com/${{ forgejo.repository }} target || {
git init --initial-branch=${{ forgejo.ref_name }} target &&
git remote set-url origin https://github.com/${{ forgejo.repository }}.git
}
- name: Filter repository
uses: https://codeberg.org/alinnow/filter-repo-action@main
with:
source: .
target: target
paths: |
README.md
LICENSE
prune_empty: never
- name: Push filtered repository
run: |
cd target
git push --force --mirror https://${{ secrets.OTHER_FORGE_TOKEN }}@github.com/${{ forgejo.repository }}It's important to name the secret for the other forge something that is not GITHUB_TOKEN, because this variable name is already used by forgejo, for compatibility with GitHub Actions.
| Input | Description | Default |
|---|---|---|
source |
Path where the source repository is checked out | . |
target |
Target directory to write the filtered repository | (required) |
paths |
Paths to include in filtered history (multi-line string) | "" |
path_globs |
Path globs to include in filtered history (multi-line string) | "" |
prune_empty |
Whether to prune empty commits | auto |