Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fork between GitHub and GitLab projects

Tags:

git

github

gitlab

Is it possible to fork a GitHub project into a GitLab project and the other way around?

like image 417
buhtz Avatar asked Jul 16 '17 14:07

buhtz


People also ask

Can I fork from GitLab to GitHub?

<Fork repository from Gilab to Github>Create an empty repository on Github with the same name as the Gitlab repository. Register Github (origin) and Gitlab (upstream) since you cloned the Gitlab repository, its origin is set to the Gitlab repository. This needs to be changed to Github.

Does fork work with GitLab?

You can fork a project in GitLab by going to the project and clicking on the Fork button. This will create a copy of the project in your own namespace. You're allowed to do whatever you want with this copy as it's is your own.

Can GitHub and GitLab work together?

GitLab CI/CD can be used with GitHub.com and GitHub Enterprise by creating a CI/CD project to connect your GitHub repository to GitLab.

What is forking a project in GitLab?

A fork is a copy of an original repository that you can put somewhere else or where you can experiment and apply changes that you can later decide if publishing or not, without affecting your original project. It takes just a few steps to fork a project in GitLab. Sign in to GitLab.


1 Answers

When creating a new repository, you can choose to import another repository, and one of the options is to import it via its https://... url from another repository site, such as github. This starts a git clone --bare <url> to import the repository. In the GitLab documentation the process is described in detail. Whenever I tried that, the process kept refreshing to the same "in progress" state indefinetly.

Update: This seems to work only for repositories you own. So to import a public repository, a workaround would be to fork it and import the fork.

So another way would be to clone the repository on the commandline before populating your new repository:

When you create a new, empty repository at your gitlab site, you get a page full of suggestions how to proceed to populate this repository. Setting up a tracker for a github site is basically a variant of the Existing Git repository recipe with the minor difference of cloning the repository to track first, and instead of renaming the previous origin to old-origin as suggested in the recipe, you want to rename it to upstream instead to maintain conventions. So you'll end up with proceedings as outlined:

  1. Clone the original repository you want to track: git clone https://github.com/<author>/<repository.git> <repository>-tracker
  2. Change into the directory the repository was cloned into cd <repository>-tracker
  3. rename the source (origin) to something else (upstream), so you can still address it. git remote rename origin upstream
  4. create your own repository located at your gitlab server, giving it a suitable name and description (don't miss to reference/link the original source there)
  5. add the url of your own gitlab repository as origin. The exact line to use including the path to your own repository can be found in the Existing Git repository recipe you probably received as a result of the previous step. git remote add origin git@<gitlab-server>/<path-to-your-repo>.git
  6. push the repository to your gitlab server: git push -u origin --all git push -u origin --tags
  7. afterwards: git remote -v origin git@<gitlab-server>/<path-to-your-repo>.git (fetch) origin git@<gitlab-server>/<path-to-your-repo>.git (push) upstream https://github.com/<author>/<repository.git> (fetch) upstream https://github.com/<author>/<repository.git> (push)
like image 160
Tatjana Heuser Avatar answered Sep 28 '22 06:09

Tatjana Heuser