Abstract
So I just hosted my own Gitea instance a few while back. It’s pretty cool and I’m very happy with how it goes. It has so many things that I can do with it, well, speaking of features, it allows me to do everything GitHub can do, but more. One feature that I like in particular is the ability to mirror repository from other Git hosting services. This is very useful for me as I can have a backup of my repositories in case something bad happens to GitHub.
GitHub in general also has something similar to the mirroring feature called GitHub Imports, except that it’s technically not a mirroring feature. It merely cloned the repository from my Gitea instance into my GitHub account and… that’s it really. So I thought for a bit, “What if I can push my code into both GitHub and Gitea at the same time?” And so I did some research and found out that it’s actually possible to do so. Here’s how you can do it.
Pushing into Two Repositories
At first, I devised a plan that involves writing out a script that will push the code into both repositories by switching the remote URL back and forth. I actually
discussed this a bit with my fellow GNU/Weeb peers while also asking how did Linus Torvalds mirror linux
repository from lore to GitHub.
They told me that Linus uses a script to push the code into both repositories at once. So I explored the idea by writing a script that does just that.
I saved the script as push.sh
and made it executable by running chmod +x push.sh
. I then ran the script by executing ./push.sh
and voila! The code is now
pushed into both repositories. Pretty nice, right? But then, I googled a bit and found out that there’s a better way to do this.
Using Multiple Remote Push URLs
Turns out, you can actually set multiple push URLs for a single repository. This is very useful as you don’t have to switch the remote URL back and forth. I got the idea from this blog post (which is an inspiration for this post anyways, kudos to whoever wrote that post). Here’s how you can do it.
And that’s it! You can now push your code into both repositories by running git push
. If you’re still not convinced, you can check the remote URL by running
git remote -v
and see that there are two push URLs for the origin
remote. For me, it looks like this:
Conclusion
So that’s how you can push your code into two repositories at once. I hope you find this post useful and if you have any questions or suggestions, feel free to email me or contact me on my handles available down the footer (well, the comment system ain’t ready yet, so…). Thanks for reading and see you in the next post!