Skip to content

Instantly share code, notes, and snippets.

@cedricziel
Created January 12, 2017 09:11
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save cedricziel/6dbf652649a98aee924dd4dc83524581 to your computer and use it in GitHub Desktop.
Save cedricziel/6dbf652649a98aee924dd4dc83524581 to your computer and use it in GitHub Desktop.
Very simple migration script to move from gitlab to gogs
#!/bin/env bash
## Needs `jq` (https://stedolan.github.io/jq/) on PATH
## and a personal gogs token of yours.
## Obtain token from https://git.example.com/user/settings/applications
## Usage:
## ./migrate.sh $clone_url $project_name [$optional_group]
## Migrate a repository to gogs into the user namespace of the token-user
## ./migrate.sh git@mygitlab.com:group/repo.git repo
## Migrate a repository to gogs into the group namespace `group` (needs to exist)
## ./migrate.sh git@mygitlab.com:group/repo.git repo group
echo $1;
clone_url=$1
name=$2
org=$3
GOGS_URL="https://git.example.com"
GOGS_TOKEN="yourpersonalgogstoken"
PWD=`pwd`
uuid=$(uuidgen)
git clone $1 $uuid;
cd $uuid;
if [ -z "$3" ]
then
clone_url=`curl -H "Authorization: token $GOGS_TOKEN" \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
--data '{"name": "'"$name"'", "description":"automatic migration", "private": true}' \
https://git.example.com/api/v1/user/repos | jq -r '.ssh_url'`
else
clone_url=`curl -H "Authorization: token $GOGS_TOKEN" \
-H "Accept: application/json" \
-H "Content-Type:application/json" \
--data '{"name": "'"$name"'", "description":"automatic migration", "private": true}' \
https://git.example.com/api/v1/org/$org/repos | jq -r '.ssh_url'`
fi
echo $clone_url;
git remote add migration $clone_url;
git push --all migration;
git push --tags migration;
cd ..;
rm -Rf $uuid;
@senz
Copy link

senz commented Aug 8, 2017

there is an api for migration now, here is a simplier version https://gist.github.com/senz/bd6f4754300f335bf051ddee1d93af5d

@wujunze
Copy link

wujunze commented Feb 7, 2018

good job

@gregdel
Copy link

gregdel commented May 6, 2018

I made a gist to migrate from gitlab to gogs using the migration API, inspired by @senz' gist
https://gist.github.com/gregdel/870d58c80b80172445dc93294531d88c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment