This repository contains a PowerShell script and a Bash Script that combines both bulk cloning GitHub repositories and pushing them to your self-hosted Gitea server. It allows you to easily clone multiple repositories from GitHub and push them to your Gitea server, without having to do it manually for each repository.
- Bulk Clone: Clone multiple GitHub repositories listed in a
repos.txtfile. - Bulk Push: After cloning, push all of the repositories to your Gitea server, either into an existing organization or under your user account.
This tool helps automate the migration or backup of multiple repositories from GitHub to Gitea with ease.
Before using this script, you must have the following:
- A Gitea server set up and running (self-hosted or otherwise).
- Git installed on your machine.
- PowerShell installed (comes pre-installed on most Windows systems) or Bash Linux
- A Personal Access Token (PAT) for Gitea with repository creation and push permissions.
- A
repos.txtfile that contains the GitHub repository URLs that you want to clone.
This script will first clone the repositories from GitHub and then push them to your Gitea server.
-
Ensure you have a
repos.txtfile in your repository folder. This file should contain the URLs of the GitHub repositories you want to clone, one per line.Example
repos.txt:https://github.com/user/repo1 https://github.com/user/repo2 https://github.com/user/repo3 -
Modify the script bulk_clone_and_push.ps1 with the following details:
- Replace the
$giteaUrlwith your Gitea server URL (e.g.,http://gitea.homelab:3000). - Replace the
$tokenwith your Gitea Personal Access Token. - Replace the
$userwith your Gitea username or organization name.(not your login uesername, but your profile username) - Ensure
$reposFilepoints to therepos.txtfile you created. - Set
$tempClonePathto the location where you want to clone the repositories temporarily.
- Replace the
-
Run the bulk_push.ps1 or .sh for Linux script:
Open PowerShell or Terminal and navigate to the directory where the script is located, and run:
.\bulk_push.ps1 or bash bulk_push.shThe script will:
- Clone each repository listed in your
repos.txtfile from GitHub. - Push each cloned repository to your Gitea server.
- Clone each repository listed in your
- If a repository already exists on Gitea, the script will skip the creation process and only push the repository content.
- If a repository doesn't exist, it will be created on your Gitea server before pushing the content.
- Error: "Repository already exists": This is expected if the repository already exists on Gitea. The script will still push the content to the repository.
- Permission Issues: Make sure your Personal Access Token has the correct permissions to create repositories and push to them on Gitea.
- Cloning Errors: Ensure you have access to the GitHub repositories and there are no authentication issues (e.g., private repositories).
Here’s the full PowerShell script that combines both the bulk clone and bulk push functionality:
Write-Host "Cloning GitHub repo: $repoUrl" $clonePath = Join-Path -Path $tempClonePath -ChildPath $repoName git clone $repoUrl $clonePath
Write-Host "Pushing repository $repoName to Gitea..."
Set-Location -Path $clonePath
$giteaRepoUrl = "http://$($user):$($token)@gitea.<domain>.<port>/$($user)/$repoName.git"
git remote set-url origin $giteaRepoUrl
git push origin --all
git push origin --tags
Write-Host "Repository $repoName pushed to Gitea successfully!"
