Synchronizing GitHub Repositories to Gitee: Manual Steps, Remote Management, and GitHub Actions
This guide explains why backing up GitHub projects to Gitee is important, details the one‑click import for existing repositories, and provides three methods—adding a remote, configuring a push source, and using GitHub Actions—to keep future code synchronized automatically.
Hello, I’m Qiufeng. Recent political controversies surrounding open‑source projects like Node and React have prompted many developers to back up their GitHub repositories to Gitee to protect their rights.
It is recommended to synchronize both existing repositories and future code changes.
Existing Repository Synchronization
Gitee provides a one‑click import feature on its website.
Steps:
1. Click the "+" button and choose "Import repository from GitHub/GitLab".
2. Authorize Gitee to access your GitHub account.
3. After authorization, select the tab to import all repositories on the current page.
Gitee will automatically import the projects; the imported repositories are private by default.
Future Code Synchronization
Although existing repositories are now on Gitee, the local remote still points to GitHub, so future commits need handling.
Option 1: Add a Remote Source
Use the familiar git remote add <name> <url> command.
Steps:
1. Add a new remote pointing to Gitee:
git remote add gitee [email protected]:hua1995116/mmt.git
2. Push changes to both remotes:
git push origin // push to GitHub
git push gitee // push to GiteeThis method requires two push commands each time.
Option 2: Add a Push Source
Remove the Gitee remote added in option 1, then set the push URL for the existing origin:
git remote rm gitee git remote set-url --add origin [email protected]:hua1995116/mmt.gitNow a single git push origin updates both platforms.
Option 3: Use GitHub Actions
Create a workflow file .github/workflows/gitee-sync.yml that triggers on every push to the master branch and mirrors the repository to Gitee using the Yikun/hub-mirror-action action.
# gitee-sync.yml
name: gitee-sync
on:
push:
branches:
- master
jobs:
repo-sync:
env:
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
gitee_user: ${{ secrets.GITEE_USER }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
persist-credentials: false
- name: sync github -> gitee
uses: Yikun/hub-mirror-action@master
if: env.dst_key && env.dst_token && env.gitee_user
with:
src: 'github/${{ github.repository_owner }}'
dst: 'gitee/${{ secrets.GITEE_USER }}'
dst_key: ${{ secrets.GITEE_PRIVATE_KEY }}
dst_token: ${{ secrets.GITEE_TOKEN }}
static_list: ${{ github.event.repository.name }}Configure three repository secrets in GitHub: GITEE_USER , GITEE_PRIVATE_KEY , and GITEE_TOKEN .
Comparison of the Three Options
Option 1
Option 2
Option 3
Advantages
1. Simple configuration
2. Control over push source
1. Simple configuration
2. Simple push
1. Complex configuration
2. Push workflow unchanged
Disadvantages
Requires two pushes each time
Cannot control source
Depends on GitHub Actions availability
Rating
⭐️⭐️⭐️
⭐️⭐️⭐️⭐️⭐️
⭐️⭐️⭐️
Recent events show that even large platforms can be affected by political actions, reinforcing the importance of backing up data.
Backup your repositories now to avoid unexpected loss.
References
[1] https://gitee.com/help/articles/4284
[2] Gitee SSH private key: https://gitee.com/profile/sshkeys
[3] Generate SSH public key: https://gitee.com/help/articles/4181#article-header0
[4] Add SSH public key to Gitee: https://gitee.com/profile/sshkeys
[5] Gitee personal access token: https://gitee.com/profile/personal_access_tokens
[6] GitHub’s response to the Ukraine war: https://github.blog/2022-03-02-our-response-to-the-war-in-ukraine/
IT Services Circle
Delivering cutting-edge internet insights and practical learning resources. We're a passionate and principled IT media platform.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.