This repository contains two Bash scripts to back up GitHub repositories and host them on your own self-hosted Git server.
Purpose:
Fetch all repositories from GitHub (personal and organization repos) and mirror them on a self-hosted Git server.
Usage:
- Ensure you have a
.netrcfile with your GitHub credentials:machine github.com login YOUR_GITHUB_USERNAME password YOUR_GITHUB_TOKEN machine api.github.com login YOUR_GITHUB_USERNAME password YOUR_GITHUB_TOKEN - Place
github-sync.shon your Git server (e.g.,/home/git/). - Make it executable:
chmod +x github-sync.sh
- Run the script:
./github-sync.sh
- All repositories will be mirrored under
/home/git/repos/.
Purpose:
Convert mirrored repositories created by github-sync.sh into independent bare repositories so they can be used independently from GitHub.
Usage:
- Place
convert-to-bare.shon your Git server (same location as mirrored repos). - Make it executable:
chmod +x convert-to-bare.sh
- Run the script:
./convert-to-bare.sh
- The script will:
- Remove the
mirrorsetting from each repo - Fetch the latest changes from origin
- Leave you with standard bare repositories that can be pushed or cloned independently
- Remove the
- Execution order: Always run
github-sync.shfirst to populate the mirrored repos, then runconvert-to-bare.shto make them independent. - Repository structure: Mirrored repos are stored as
.gitdirectories under/home/git/repos/. - Cloning: After conversion, you can clone repositories from your server:
git clone git@your-server:repo-name
- Dependencies: Both scripts require
jqandcurlto fetch repository lists from GitHub.
MIT License