Skip to content

Migrating all GitHub repositories to Gitea

Migrate every GitHub repository, private and public, to Gitea with one shell script that calls both APIs. It moves the code only, not issues or wikis.

1 min read

To migrate all your GitHub projects (both private and public) to a Gitea instance (may work with Gogs as well - not tested) you can use the attached script below. It uses the Gitea API to start a migration for every project as returned by the GitHub API. You will need to generate a token at Github and Gitea for this to work.

By default it imports every repository as private because of a bug in Gitea which exposes private repositories in users’ public activity feeds if the repository has been made private after the initial import.

GITHUB_USERNAME=
GITHUB_TOKEN=
GITEA_USERNAME=
GITEA_TOKEN=
GITEA_DOMAIN=

for url in `curl -u "$GITHUB_USERNAME:$GITHUB_TOKEN"
  --url https://api.github.com/user/repos?per_page=100 | jq -r '.[] | "\(.clone_url)"'`; do

  name=`echo $url | rev | cut -d'/' -f1 | rev | rev | cut -c 5- | rev`
  curl --header "Authorization: token $GITEA_TOKEN" --request POST \
    --url https://$GITEA_DOMAIN/api/v1/repos/migrate --header 'content-type: application/json' \
    --data "{\"clone_addr\": \"$url\",
             \"uid\": 1,
             \"repo_name\": \"$name\",
             \"auth_username\": \"$GITEA_USERNAME\",
             \"auth_password\": \"$GITEA_TOKEN\",
             \"private\": true}"
  done

Further reading