DEV Community

Cover image for How To Setup A Self Hosted Github Mirror ?
Varun Sridharan
Varun Sridharan

Posted on

How To Setup A Self Hosted Github Mirror ?

Why ?

What I’m trying to accomplish is a fail-safe in case something happens to GitHub which would make me loose access, be that voluntarily or involuntarily.

I am not migrating away from GitHub because I see no reason to: the platform is very useful to me, and I’d not like to loose it.

Why Gitea

I’d like a Web UI onto these repositories in addition to the files in the file system. It could have been Gitlab, but I think Gitea is probably the option with the lowest resource requirements.

When I add a repository to Gitea and specify I want it to be mirrored, Gitea will take charge of periodically querying the source repository and pulling changes in it.

How To ?

After setting up Gitea and creating a user, I create an API token in Gitea with which I can create repositories programmatically.

Then you will also need to create a Personal Access Token In Github with the below scope

  1. Select public_repo scope if you just want to mirror Public Gist / Repo to your mirror
  2. Select repo scope if you want to mirror both public & private Gist / Repo to your mirror
  3. Select gist scope if you want to mirror private gists.

Installation

  1. Install Python3 sudo apt-get install python3
  2. Install PIP3 sudo apt-get install python3-pip
  3. Install PyGithub pip install PyGithub

Once everything is installed.

Clone / Download this repo https://github.com/varunsridharan/github-gitea-mirror

And update src/config.json with your information And run the below cmd

Mirror Everything

Below CMD Will mirror (Public / Private ) Repository, Gists Forks & Stared Repos

python3 mirror.py 
Enter fullscreen mode Exit fullscreen mode

Mirror Source Gists

python3 gist.py
Enter fullscreen mode Exit fullscreen mode

Mirror Stared Gists

python3 giststared.py
Enter fullscreen mode Exit fullscreen mode

Mirror Source Repository

python3 repoSource.py 
Enter fullscreen mode Exit fullscreen mode

Mirror Forked Repository

python3 repoForked.py
Enter fullscreen mode Exit fullscreen mode

Mirror Stared Repository

python3 repoStared.py
Enter fullscreen mode Exit fullscreen mode

GitHub logo varunsridharan / github-gitea-mirror

Simple Python Script To Mirror Repository From Github To Gitea

Simple Python Script To Mirror Repository / Gist From Github To Gitea

Why ?

I am a data hoarder.

I am not migrating away from GitHub because I see no reason to: the platform is very useful to me, and I’d not like to lose it. What I’m trying to accomplish is a fail-safe in case something happens to GitHub which would make me lose access, be that voluntarily or involuntarily.

✅ Requirements

  1. Python3 -- sudo apt-get install python3
  2. PyGithub -- pip install PyGithub

⚙️Installation

Github Clone

Just run the below cmd in your Gitea server

git clone https://github.com/varunsridharan/github-gitea-mirror

Or you can download the source code and install it where ever you need

🚀 Usage

Github Access Token Scopes

  • if you want to mirror private repos then select everything under Repo scope
  • if you want to mirror public repos then select repo.public_repo scope
  • if you want to mirror secret Gists…




Top comments (0)