Knowledge Base

Preserving for the future: Shell scripts, AoC, and more

Migrating github projects to gitlab

For the projects that have issues, wikis, and all those nice addons, use the GitLab GitHub importer tool. For simple projects, you can just call them from the command line. See https://gitlab.com/bgstack15/former-gists/blob/master/migrate.sh.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
# https://stackoverflow.com/questions/20359936/import-an-existing-git-project-into-gitlab/30483494#30483494

username="bgstack15"
repo="${1}"

func() {
   git clone --mirror "https://github.com/${username}/${repo}" "./${repo}"
   pushd "${repo}"
   git remote add gitlab "https://gitlab.com/${username}/${repo}.git"
   git push gitlab --mirror
   popd
}

time func ;

#Now if you have a locally cloned repository that you want to keep using with the new remote, just run the following commands* there:
#
#git remote remove origin
#git remote add origin "http://gitlab.example.com/${username}/${repo}.git"
#git fetch --all

Comments