# Batch-migrating Gitolite repositories to Gogs

<p class="callout info">This article was originally published at [https://gist.github.com/joepie91/2ff74545f079352c740a](https://gist.github.com/joepie91/2ff74545f079352c740a). </p>

<div class="Box-body readme blob p-5 p-xl-6 gist-border-0" id="bkmrk-note%3A-this-will-only"><article class="markdown-body entry-content container-lg">**NOTE:** This will only work if you are an administrator on your Gogs instance, or if an administrator has enabled local repository importing for all users.

First, save the following as `migrate.sh` somewhere, and make it executable (`chmod +x migrate.sh`):

```bash
HOSTNAME="git.cryto.net"
BASEPATH="/home/git/old-repositories/projects/joepie91"

OWNER_ID="$1"
CSRF=`cat ./cookies.txt | grep _csrf | cut -f 7`

while read REPO; do
	REPONAME=`echo "$REPO" | sed "s/\.git\$//"`
	curl "https://$HOSTNAME/repo/migrate" \
		-b "./cookies.txt" \
		-H 'origin: null' \
		-H 'content-type: application/x-www-form-urlencoded' \
		-H "authority: $HOSTNAME" \
		--data "_csrf=$CSRF" \
		--data-urlencode "clone_addr=$BASEPATH/$REPO" \
		--data-urlencode "uid=$OWNER_ID" \
		--data-urlencode "auth_username=" \
		--data-urlencode "auth_password=" \
		--data-urlencode "repo_name=$REPONAME" \
		--data-urlencode "description=Automatically migrated from Gitolite"
done
```

Change `HOSTNAME` to point at your Gogs installation, and `BASEPATH` to point at the folder where your Gitolite repositories live on the filesystem. It must be the entire base path - the repository names cannot contain slashes!

Now save the Gogs cookies from your browser as `cookies.txt`, and create a file (eg. `repositories.txt`) containing all your repository names, each on a new line. It could look something like this:

```
project1.git
project2.git
project3.git
```

After that, run the following command:

```bash
cat repositories.txt | ./migrate.sh 1
```

... where you replace `1` with your User ID on your Gogs instance.

Done!

</article></div>