Operations 9 min read

Using GitHub Actions to Continuously Sync Repositories to Gitee

This guide explains how to configure GitHub Actions to automatically synchronize GitHub repositories with Gitee, covering the basics of GitHub Actions, synchronization methods, action selection or creation, required preparation steps, workflow syntax, and practical code examples.

DevOps Cloud Academy
DevOps Cloud Academy
DevOps Cloud Academy
Using GitHub Actions to Continuously Sync Repositories to Gitee

GitHub Actions is GitHub's built-in CI/CD automation feature, fully open since November 2019, offering extensive event support, reusable actions, and flexible runners that can be hosted by GitHub or self‑hosted.

Because GitHub's servers are overseas and sometimes inaccessible, many developers still prefer GitHub but need to mirror their code to Gitee, which is hosted domestically. Synchronization can be done via Gitee's import tool, manual dual‑push, or, most conveniently, using a GitHub Action.

The tutorial recommends the Yikun/hub-mirror-action from the GitHub Marketplace to perform the sync. The action's syntax is similar to GitLab CI and supports various scenarios such as organization sync, whitelist/blacklist filtering, static lists, SSH cloning, forced updates, and timeout settings.

Preparation steps include generating an SSH key pair, adding the private key as a secret GITEE_PRIVATE_KEY in the GitHub repository, and adding the public key to Gitee's SSH settings; then creating a Gitee personal access token and storing it as secret GITEE_TOKEN in GitHub.

A workflow file .github/workflows/SyncToGitee.yml is created with the following core content:

name: Sync Github Repos To Gitee

on:
  push:
    branches:
      - master

jobs:
  build:
    runs-on: ubuntu-20.04
    steps:
      - name: Sync Github Repos To Gitee
        uses: Yikun/[email protected]
        with:
          src: github/Hargeek
          dst: gitee/ssxr
          dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
          dst_token: ${{ secrets.GITEE_TOKEN }}
          account_type: user
          clone_style: "https"
          debug: true
          force_update: true
          static_list: "python-nianbao-struct"
          timeout: '600s'

The on section defines trigger conditions, while the jobs section specifies the steps, with uses invoking the external action. Additional parameters control cloning method, debugging output, forced updates, repository lists, and timeout.

When the workflow runs, the action checks if the target repository exists on Gitee, creates it if necessary, and then force‑pushes the code. Execution logs show package installations, cloning, repository creation, and push results.

After committing the workflow, GitHub displays the run status, and the corresponding repository appears on Gitee with identical content. Subsequent pushes to GitHub automatically trigger the sync.

In summary, using GitHub Actions to mirror repositories to Gitee provides a powerful, flexible, and automated solution for developers who need to maintain code in both platforms.

CI/CDautomationDevOpsGiteeGitHub Actionsrepository-sync
DevOps Cloud Academy
Written by

DevOps Cloud Academy

Exploring industry DevOps practices and technical expertise.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.