How to migrate GitHub repository to GitLab?

import Image from ‘@components/Image.astro’

Gitlab and GitHub are cloud hosting services for managing git repositories. It provides private and public repositories with more features like CI and CD functionalities Sometimes, You have a repository in Github. you want to migrate the git repository to GitLab.

This tutorial explains two ways to migrate to the GitLab repository.

You have access to and with credentials

How to migrate the repository from GitHub to GitLab?

A first approach using the User interface

  • First, log in to by giving the credentials

  • Once user logged in, Header navigation click on + icon and select `Create New Project/Repository

  • Select Import project on the Create Project screen as a given screenshot

Gitlabe create project import
  • Select Repository By URL as given below

  • Import Project with repository URL
  • It is redirected to the following page

Gitlab project configuration details

and enter the following details

  • Git Repository URL: This is a public git repository, If it is a private repository, First you need to authenticate with git with the below user and password details

  • username and password: These are optional and can be used when the git repository is private

  • Project Name: Gitlab project

  • Next, Create a Project

  • Once Import is done, You have a GitLab project created with code

  • It imports all branches, and commits the history of files and configurations from the git repository

Command line to transfer Gitlab to GitHub repository

Following are steps with the command line using the git command

  • First, create a Proect in GitLab
  • Goto dashboards🔗
  • Click on New project
  • Create a Blank project and provide the following details
    • Project name: node-unittest
    • slug: node-unittest
    • Next, Create a project
  • It creates an empty project in Gitlab

Next, Open the Terminal

  • create a directory using mkdir nodetest command
  • Run the below commands to clone git repository
git clone --mirror
  • Change directory using cd nodetest.git
cd nodetest.git
  • chnage remote repository to gitlab(newly created repository)
git remote add gitlab

Next, push changes with all commits, and branches into GitLab with the below command

git push gitlab --mirror

if the above commands succeed, It imports the project successfully.

If the above command throws the below error

! [remote rejected] main (pre-receive hook declined)
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to ''

Please run the set of below commands

git remote remove origin
git remote add origin
git fetch --all
git push -u origin --all