6

I would like to fork a GitLab repository (not my own, and public), so I can make changes to my fork, and update that fork with the upstream version whenever there are upstream updates, using GitHub desktop.

So far, what I have done is:

(1) imported the GitLab repo on github.com -> import repository , the repository appears on GitHub as my own (which it is not) and not as a fork (which I want it to be)

(2) on GitHub desktop, add repository -> clone GitHub repository from (1) on my local machine, make changes to it, push the changes to my GitHub repository (good)

(3) if there are any changes made to the upstream GitLab repository, I cannot merge those into my GitHub repository. Indeed, the latter is not considered a fork and it is not connected in any way to the upstream GitLab repository. Normally I would use on GitHub desktop "Choose a branch to merge into master", choose the upstream branch, and merge the changes.

(4) I tried "git remote add upstream {gitlab repo}" but that did not change anything.

(5) also tried, alternatively, just cloning the GitLab repository directly on my local machine, making changes to it, but pushing my changes attempts to push them on GitLab, which I cannot do and do not want to do as the repo isn't mine.

Emma Carli
  • 63
  • 1
  • 7
  • Why can't you update your github repo with the changes you have pulled from gitlab? – mnestorov Nov 26 '20 at 14:24
  • 1
    I am not sure I understand the whole problem. So, there's a repo in gitlab... you cloned it. And then you set up another repo in github and added it as a second remote to your local repo.... and then pushed the branches into github. So, locally, you have 2 remotes. gitlab (origin?) and github (another-remote). So far, that sounds pretty simple. What's the roadblock from there? Because you should be able to push any branch into whatever of the 2 remotes that you are playing with.... or did I miss something? – eftshift0 Nov 26 '20 at 14:49
  • Perhaps an example of the workflow that you are following (or trying to follow) to bring changes from one repo to the other might help us understand what you wan to achieve, – eftshift0 Nov 26 '20 at 14:52
  • Thank you for your comments, I added my attempt. – Emma Carli Nov 26 '20 at 15:51
  • As far as I know, github doesn't talk directly to gitlab, so there is no way to make a "fork" on github that knows about gitlab. You're probably forced to handle the bridging between those two systems yourself. – Lasse V. Karlsen Nov 26 '20 at 15:54
  • @LasseV.Karlsen in that case, how would you go about merging the upstream GitLab branch from time to time, please? – Emma Carli Nov 26 '20 at 16:01
  • I didn't say anything about fetching because I assumed it was understood that that is the operation you would use to be able to see the updates from each remote. I'm glad you were able to solve it. – eftshift0 Nov 26 '20 at 16:35

2 Answers2

5

What you are asking for is unfortunately not possible using the Gitlab and GitHub websites. What you can do is to add the upstream remote locally and merge the changes manually.

What you did in step 4 is already a step in the right direction. What you need to do in order to merge the upstream is to fetch and merge. Like this:

git remote add upstream {gitlab repository}

Now fetch the upstream. This will download commits, files, and refs from the Gitlab repository.

git fetch upstream

Then you can merge branches from the upstream into your local repository. Be aware that you may have to resolve conflicts.

git merge upstream/master

To publish the changes, push them to the origin. In this case GitHub. The origin remote is the default namespace, meaning that when you pull the master branch, for example using git pull master, the GitHub master branch is pulled.

git push

Sources:

Tom
  • 4,070
  • 4
  • 22
  • 50
  • 2
    "git fetch upstream" was what I needed ! Now I can merge the upstream changes using GitHub desktop. Thank you! – Emma Carli Nov 26 '20 at 16:32
1

You are almost there with updating your GitHub repo with the remote changes from GitLab. All you need to do is:

git fetch <gitlab remote> # or git pull or pull --rebase

Then you push to your GitHub repo

git push <github remote> <branch name> 

Basically, your workflow is pull from GitLab -> push to GitHub. A more detailed answer could be found here.

I am not aware for any existing integration between GitLab and GitHub, that would classify your repository as forked on GitHub.

You can do this process as often as you would like. It's just manual work for you.

If you are looking into automating this process, you can take a look at cron jobs, but that is a totally different topic.


(4) I tried "git remote add upstream {gitlab repo}" but that did not change anything.

This just adds another remote to your list of remotes. By itself, it doesn't do anything. You have to push to that remote in order to start making changes.


Also, since you are doing this, check if the project you are working on if it has a LICENSE. That would be helpful in such a case.

mnestorov
  • 4,116
  • 2
  • 14
  • 24