In This Article, I will be discussing two methods through which we can migrate a Repository from github to Gitlab.
So there are Basically Two methods through which we can migrate a repository from Github to Gitlab. First is through UI which is Quite easy.
As you may very well know, Gitlab is among the best alternatives to Github, the first that comes to mind, from the available options. Gitlab is a scalable and efficient Git-based fully featured platform for software development: it supports a complete DevOps lifecycle.
Let’s Migrate a Repository through UI Dashboard. After successfully signing in, go to the top navigation bar, click on
+ and choose New project and enter path of your New Project as shown.
Next, click on the Import project tab and then choose GitHub from the available options as shown in the screenshot.
Click on Authenticate with Github. You will be redirected to a page as shown. You can also use personal access token also for authentication.
An external application authorization page will appear to authorize the GitLab, as shown in this screenshot. Click Authorize gitlabhq.
After Authentication. You will be redirected back to Gitlab’s import page where you should see a list of all your GitHub repositories. Click on Import from the status column, for each repository you want to import from Github to Gitlab.
Once your repository is imported, its status will change to Complete as shown in this screenshot.
You can go visit your project now, This was through UI. Now we will another way of importing the project through command line.
Migrating Repository through Command Line
First of all get onto gitlab and create a new Project. Next go on Github and select which project you want to migrate.
First we will clone this repository from Github to our local with git clone command followed by our repository URL.
I will clone this repository.
Whenever we clone any repository it also has a .git directory which contains the metadata about the this repository.
Now to migrate this repository we have to something callled bare clone. Let’s us first do a bare clone
git clone --bare <url>
After this you will notice, it has made one more folder with .git extension. Now what happens is whatever was present in .git folder is now there in this directory.
Now finally to push this to gitlab, First do Change directory to pipeline.git.we will use this command, do make sure you have created a new project as i did in earlier steps.
while pushing we need to give this URL as shown in this diagram above.
git push --mirror https://gitlab.com/rishirai/demo-project.git
now you will be asked your gitlab username and password.
After entering your id and password, You will see you have sucessfully pushed this on Gitlab.
Note: If you get any error while pushing then please do check if your branch name is under protected list or not in gitlab. If your branch name is under protected list on gitlab then you will not be able to push.
In this Article we saw, how we can migrate from a repository from github to gitlab using two methods. If you liked this blog. Please like and share and if you have any doubts feel free to reach out to me.