Sync Your GitHub Project to Gitee (and Other Git Hosts) with One Config
This guide shows how to create matching repositories on GitHub and Gitee, configure a single local Git repository to push to both remotes, and keep them synchronized automatically, providing step‑by‑step commands, config file edits, and practical tips for developers.
Introduction
GitHub is widely used, but in some regions its speed is slow and images may not load. Gitee (码云) offers faster access in China. By mirroring a project on both platforms you can increase visibility and avoid network issues.
Create Repositories
GitHub
Log in to GitHub and create a new repository (or use an existing one). The article shows a screenshot as an example.
Gitee
On Gitee, create a repository with the same name. During creation select “Import existing repository” and paste the HTTPS URL of the GitHub repo. Gitee will clone the GitHub repository and sync the contents.
Manual Synchronization
If you push changes only to GitHub, Gitee will not update automatically. You can manually trigger a sync from the Gitee project page by clicking the sync icon, which is suitable for occasional updates.
Automatic Synchronization via Git
Configure your local Git repository to push to both remotes. The steps below assume a macOS environment; similar commands work on other OSes.
Clone the GitHub repository
git clone [email protected]:secbr/shiro.gitEnter the project directory; the hidden .git folder contains the configuration. ls .git Typical output includes files such as config, HEAD, refs, etc.
Edit .git/config
Open the config file with vi (or any editor). The original content looks like:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = [email protected]:secbr/shiro.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/mainAdd a second url line under the same remote section that points to the Gitee repository (the SSH address must match the Gitee account’s key):
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = [email protected]:secbr/shiro.git
url = [email protected]:secbro/shiro.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "main"]
remote = origin
merge = refs/heads/mainNow the same remote named origin has two URLs. When you push, Git will send the commits to both GitHub and Gitee.
Pushing Changes
After editing files, commit locally and push:
git add .
git commit -m "Update README"
git push origin mainThe push operation updates both repositories simultaneously, instantly increasing the project’s exposure.
Conclusion
Using a single .git/config modification you can keep multiple Git hosting services in sync without manual copying. The same approach works for GitLab, Bitbucket, or self‑hosted Git servers. For best performance, limit the number of simultaneous remotes to two to avoid long network delays.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Senior Brother's Insights
A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.
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.
