How to fork a GitLab repository to GitHub?
Answer a question
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.
Answers
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:
- https://www.atlassian.com/git/tutorials/git-forks-and-upstreams
- https://www.atlassian.com/git/tutorials/syncing/git-fetch
更多推荐


所有评论(0)