Open In App

Forking Git Repository From GitHub to GitLab

Last Updated : 10 Sep, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

Forking Git Repository from GitHub to GitLab allows you to make changes, experiment, or contribute to a project without affecting the source. This is useful when you want to work on open-source projects or collaborate with teams across different platforms.

In this article, we'll see how to Fork Git Repository From GitHub to GitLab, maintaining all the project history and branches.

Steps For Forking Git Repository From GitHub to GitLab

Step 1: Clone the GitHub Repository

git clone https://github.com/username/repository-name.git
cd repository-name

You must replace the "username" and "repository name" with your project requirements.

Step 2: Create a New GitLab Repository

Once we are done with cloning the repository in our system, now our new task is to create a new GitLab repository, which we can be created by navigating directly to the plus icon at the top.

Step 3: Add the GitLab Remote to Your Local Repository

Next, we need to add the GitLab repository as a remote to our local repository which we can do by entering the following command.

 git remote add gitlab https://gitlab.com/username/repository-name.git

Step 4: Push the Repository to GitLab

Now it's time to push the cloned repository to our created GitLab repository by using the following command.

git push gitlab main

See we are pushing to the main branch in our case you can change for yourself

Step 5: Set GitLab as the Default Remote (Optional)

This going to be an optional task which can be skipped but those who want to use gitlab primarily, they can remove the current remote and then rename the gitlab remote to the origin by usng the following command

git remote remove origin
git remote rename gitlab origin

Example 1: Cloning and Adding GitLab as Remote

For this article we are considering a project named "OLauncher" which is hosted on Github which we are going to fork on Gitlab.

Step 1: First we Clone Repo to our Local system Using This command

git clone https://github.com/tanujnotes/Olauncher.git
Git-clone
Git clone

Step 2: Create a new Gitlab repository naming "OLauncher"

Step 3: Add a remote for Gitlab

git remote add gitlab https://gitlab.com/gfg-tutorial/gfg-forking-github-to-gitlab.git
Gitlab-Repo
Gitlab Repo


Step 4: Know the Git Branch

git branch -v
git-branch--v
git branch -v

Step 5: Push the Repo to the branch from the local System to Gitlab

git push gitlab master

Git-clone
git push
Gitlab-Output
Forking Git Repository From GitHub to GitLab

Example 2: Removing GitHub Remote and Renaming GitLab

If we want to remove Github connection and focus solely on Gitlab. As said Earlier this is an Optional case

git remote remove origin
git remote rename gitlab origin

By Following this Guide we can fork any project from Github to Gitlab with ease.


Next Article

Similar Reads