问题
Suppose that I would like to implement a fix to a project of someone else. That project resides on GitHub.
I could create a fork on GitHub and implement the fix.
However, I would like to create my fork on GitLab rather than on GitHub.
Is that possible? How?
I have read this article: https://about.gitlab.com/2016/12/01/how-to-keep-your-fork-up-to-date-with-its-origin/
Anyway, I am not sure what should I do in my case.
- Should I just create a fork on GitLab of the project from GitHub somehow?
- Or should I create a mirror on GitLab of the project from GitHub?
- Or should I create a mirror on GitLab and then fork the mirror?
- Or should I do something completely different?
What is the correct approach.
Thanks.
UPDATE
Repository mirroring on GitLab does not make sense probably. I can create a mirror of MY GitHub repository on GitLab but I cannot create a mirror of a repository of someone else.
https://docs.gitlab.com/ee/workflow/repository_mirroring.html
This is what I have done so far:
I have cloned the original GitHub project to my local machine. I have commited the fix to a new branch in my local repository. I have created an empty project on GitLab. I have set origin in my local repository to that empty project on GitLab and pushed both branches to GitLab. I have set upstream in my local repository to the GitHub repository.
When I want to get new commits from the original GitHub repository to the repository on GitLab (i.e. sync the repositories), I can do this using my local repo as an intermediate step. However, there is no direct connection between the repo on GitHub and the repo on GitLab. Is my setup correct? Is there any difference if I make a fork on GitHub?
回答1:
If you just want to track changes, first make an empty repository in GitLab (or whatever else you may be using) and clone it to your computer.
Then add the GitHub project as the "upstream" remote with:
git remote add upstream https://github.com/user/repo
Now you can fetch and pull from the upstream should there be any changes. (You can also push or merge to it if you have access rights.)
git pull upstream master
Finally, push back to your own GitLab repository:
git push origin master
If you don't want to manually pull upstream/push origin, GitLab offers a mirroring ability in Settings => Repository => Mirroring repositories.
回答2:
The browser-only way:
- Create a new project in Gitlab (Just an empty project with a name is fine)
- Go to Settings -> Respository
- Enter GitHub URL under 'Mirroring repositories'
- Make sure 'Mirror direction' is 'Pull'
- Press 'Mirror repository' button
- Press the sync icon next to the entry that appears
回答3:
Forking a private github repository is possible.
- Click new project
- Select Import
- Select github
- OAuth2 used to authenticate and auto create gitlab app
- Select project to fork
^ I've just done this with a private repo on github, imported successfully (inc branches etc). Imported project is automatically kept private ;)
回答4:
Instead of forking, you can import any publicly available GitHub repository using only the web interface:
- From your GitLab dashboard click New project
- Switch to the Import project tab
- Click on the Repo by URL button
- Fill in the "Git repository URL" and the remaining project fields
- Click Create project to begin the import process
- Once complete, you will be redirected to your newly created project
Used this technique recently, and it works on any public repository even without a GitHub account. See this GitLab docs page for the source of info.
来源:https://stackoverflow.com/questions/50973048/forking-git-repository-from-github-to-gitlab