Forking Git repository from GitHub to GitLab

前端 未结 4 532
渐次进展
渐次进展 2021-01-29 19:54

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.

相关标签:
4条回答
  • 2021-01-29 20:25

    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.

    0 讨论(0)
  • 2021-01-29 20:26

    Instead of forking, you can import any publicly available GitHub repository using only the web interface:

    1. From your GitLab dashboard click New project
    2. Switch to the Import project tab
    3. Click on the Repo by URL button
    4. Fill in the "Git repository URL" and the remaining project fields
    5. Click Create project to begin the import process
    6. 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.

    0 讨论(0)
  • 2021-01-29 20:30

    The browser-only way:

    1. Create a new project in Gitlab (Just an empty project with a name is fine)
    2. Go to Settings -> Respository
    3. Enter GitHub URL under 'Mirroring repositories'
    4. Make sure 'Mirror direction' is 'Pull'
    5. Press 'Mirror repository' button
    6. Press the sync icon next to the entry that appears
    0 讨论(0)
  • 2021-01-29 20:41

    Forking a private github repository is possible.

    1. Click new project
    2. Select Import
    3. Select github
    4. OAuth2 used to authenticate and auto create gitlab app
    5. 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 ;)

    0 讨论(0)
提交回复
热议问题