forgejo-to-github is a Bash script designed to streamline the creation and synchronization of repositories between Forgejo and GitHub. This tool:
- Automatically creates repositories on both Forgejo and GitHub.
- Initializes version control locally with optional language templates.
- Sets up mirroring between Forgejo and GitHub for seamless synchronization.
Before using the script, ensure you have the following:
- Forgejo and GitHub Accounts:
- Forgejo Server URL and Forgejo user token with repository permissions.
- GitHub user token with
repopermissions.
- Environment Variables:
- Add the following variables to your shell configuration (
~/.bashrcor~/.zshrc):
- Add the following variables to your shell configuration (
export FORGEJO_URL="http://<forgejo-server-url>:<port>"
export FORGEJO_USER="<your-forgejo-username>"
export FORGEJO_TOKEN="<your-forgejo-personal-token>"
export GITHUB_USER="<your-github-username>"
export GITHUB_TOKEN="<your-github-personal-token>"Make sure to reload your shell after editing the configuration:
source ~/.bashrcExecute the git-create script to create and initialize repositories:
./git-create [repository-name]The script guides you through the following steps interactively:
-
Visibility Selection: Choose whether the repository is
PrivateorPublic. -
Setup Language:
Go: Initializes a Go project.Python: Creates a Python project.Bash: Sets up a Bash script template.Exit: Cancels the process.
-
Mirroring:
- Mirrors changes from Forgejo to GitHub with automatic push synchronization.
- Run the script:
./git-create my-private-repo
- Select Private when prompted.
- Choose Bash for the project language.
- Follow on-screen instructions for initialization.
During the setup process, choose:
porP: For private repositories.- Any other key: For public repositories.
The script creates repositories on:
- GitHub using its REST API.
- Forgejo using its API. Ensure the
FORGEJO_URLis correct.
Automatically configures basic project templates:
- Go: Initializes
go.modand main function. - Python: Sets up a Python script (
main.py). - Bash: Prepares a Bash script (
main.sh) with execution permissions.
Automatically configures push mirroring:
- Syncs changes from Forgejo to GitHub every 8 hours.
- Mirrors commits with the
forgejoremote alias.
If required environment variables are unset, the script will terminate with:
Error: FORGEJO_TOKEN or GITHUB_TOKEN not found in environment.
Solution: Make sure all variables are properly set (review the Prerequisites section).
The script doesn't check if a repository already exists. Ensure the repository name is unique.
Feel free to submit issues or contribute to enhance the functionality of forgejo-to-github!
This project is licensed under the MIT License.