Forking Git Repository From GitHub to GitLab
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.
Table of Content
- Steps For Forking Git Repository From GitHub to GitLab
- Example 1: Cloning and Adding GitLab as Remote
- Example 2: Removing GitHub Remote and Renaming GitLab
- Forking Git Repository From GitHub to GitLab -FAQs
- Can I directly fork a GitHub repository to GitLab?
- How do I keep my GitHub and GitLab repositories in sync after forking?
- What happens to my branches and tags when I fork a GitHub repository to GitLab?
- Do I need permissions to fork a private GitHub repository to GitLab?
- How do I add a GitLab repository as a remote to a cloned GitHub repository?
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

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

Step 4: Know the Git Branch
git branch -v

Step 5: Push the Repo to the branch from the local System to Gitlab
git push gitlab master


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.