将现有的 git 项目导入 GitLab?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20359936/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Import an existing git project into GitLab?
提问by rubo77
I have an account of a Gitlab installation where I created the repository "ffki-startseite"
我有一个 Gitlab 安装帐户,我在其中创建了存储库“ffki-startseite”
Now I want to clone the repository git://freifunk.in-kiel.de/ffki-startseite.git
into that repository with all commits and branches, so I can start working on it in my own scope.
现在我想将存储库克隆git://freifunk.in-kiel.de/ffki-startseite.git
到包含所有提交和分支的存储库中,这样我就可以在我自己的范围内开始处理它。
How can I import it?
我怎样才能导入它?
采纳答案by rubo77
Moving a project from GitHub to GitLab including issues, pull requests Wiki, Milestones, Labels, Release notes and comments
将项目从 GitHub 移至 GitLab,包括问题、拉取请求 Wiki、里程碑、标签、发行说明和评论
There is a thorough instruction on GitLab Docs:
GitLab Docs 上有详尽的说明:
https://docs.gitlab.com/ee/user/project/import/github.html
https://docs.gitlab.com/ee/user/project/import/github.html
tl;dr
tl;博士
Ensure that any GitHub users who you want to map to GitLab users have either:
- A GitLab account that has logged in using the GitHub icon - or -
- A GitLab account with an email address that matches the public email address of the GitHub user
From the top navigation bar, click + and select New project.
- Select the Import project tab and then select GitHub.
- Select the first button to List your GitHub repositories. You are redirected to a page on github.com to authorize the GitLab application.
- Click Authorize gitlabhq. You are redirected back to GitLab's Import page and all of your GitHub repositories are listed.
- Continue on to selecting which repositories to import.
确保您想要映射到 GitLab 用户的任何 GitHub 用户具有:
- 使用 GitHub 图标登录的 GitLab 帐户 - 或 -
- GitLab 帐户,其电子邮件地址与 GitHub 用户的公共电子邮件地址相匹配
在顶部导航栏中,单击 + 并选择新建项目。
- 选择导入项目选项卡,然后选择 GitHub。
- 选择第一个按钮以列出您的 GitHub 存储库。您将被重定向到 github.com 上的页面以授权 GitLab 应用程序。
- 单击授权 gitlabhq。您将被重定向回 GitLab 的导入页面,并列出您的所有 GitHub 存储库。
- 继续选择要导入的存储库。
But Please read the GitLab Docs pagefor details and hooks!
但是请阅读GitLab 文档页面了解详细信息和钩子!
(it's not much)
(不是很多)
回答by raveren
I was able to fully export my project along with all commits, branches and tagsto gitlab via following commands run locally on my computer:
通过在我的计算机上本地运行的以下命令,我能够将我的项目以及所有提交、分支和标签完全导出到 gitlab:
To illustrate my example, I will be using https://github.com/raveren/kintas the source repository that I want to import into gitlab. I created an empty project named
Kint
(under namespaceraveren
) in gitlab beforehand and it told me the httpgit url of the newly created project there is http://gitlab.example.com/raveren/kint.gitThe commands are OS agnostic.
为了说明我的示例,我将使用https://github.com/raveren/kint作为要导入 gitlab 的源存储库。我事先在 gitlab 中创建了一个名为
Kint
(在 namespace 下raveren
)的空项目,它告诉我新创建的项目的httpgit url 有http://gitlab.example.com/raveren/kint.git这些命令与操作系统无关。
In a newdirectory:
在新目录中:
git clone --mirror https://github.com/raveren/kint
cd kint.git
git remote add gitlab http://gitlab.example.com/raveren/kint.git
git push gitlab --mirror
Now if you have a locally cloned repository that you want to keep using with the new remote, just run the following commands* there:
现在,如果您有一个本地克隆的存储库并希望继续与新远程一起使用,只需在那里运行以下命令*:
git remote remove origin
git remote add origin http://gitlab.example.com/raveren/kint.git
git fetch --all
*This assumes that you did not rename your remote master from origin
, otherwise, change the first two lines to reflect it.
*这假设您没有重命名您的远程主机 from origin
,否则,更改前两行以反映它。
回答by rubo77
Add the new gitlab remote to your existing repository and push:
将新的 gitlab 远程添加到您现有的存储库并推送:
git remote add gitlab url-to-gitlab-repo
git push gitlab master
回答by Jamie Hutber
To keep ALL TAGS AND BRANCHES
保留所有标签和分支
Just simply run this command in an existing Git repository
只需简单地在一个 existing Git repository
cd existing_repo
git remote rename origin previous-hosts
git remote add gitlab [email protected]:hutber/kindred.com.git
git push -u gitlab --all
git push -u gitlab --tags
回答by Rajkaran Mishra
Here are the steps provided by the Gitlab:
以下是 Gitlab 提供的步骤:
cd existing_repo
git remote rename origin old-origin
git remote add origin https://gitlab.example.com/rmishra/demoapp.git
git push -u origin --all
git push -u origin --tags
回答by Martijn van Wezel
This is a basic move one repo to new location. I use this sequence all te time. With --bareno source files will be seen.
这是将一个 repo 移动到新位置的基本操作。我一直使用这个序列。使用--bare将看不到源文件。
Open Git Bash.
Create a bare clone of the repository.
打开 Git Bash。
创建存储库的裸克隆。
git clone --bare https://github.com/exampleuser/old-repository.git
Mirror-push to the new repository.
镜像推送到新的存储库。
cd old-repository.git
git push --mirror https://github.com/exampleuser/new-repository.git
Remove the temporary local repository you created in step 1.
删除您在步骤 1 中创建的临时本地存储库。
cd ../
rm -rf old-repository.git
Why mirror? See documentation of git: https://git-scm.com/docs/git-push
为什么要镜像?查看 git 文档:https: //git-scm.com/docs/git-push
--all Push all branches (i.e. refs under refs/heads/); cannot be used with other .
--mirror Instead of naming each ref to push, specifies that all refs under refs/ (which includes but is not limited to refs/heads/, refs/remotes/, and refs/tags/) be mirrored to the remote repository. Newly created local refs will be pushed to the remote end, locally updated refs will be force updated on the remote end, and deleted refs will be removed from the remote end. This is the default if the configuration option remote..mirror is set.
--all 推送所有分支(即 refs/heads/ 下的 refs);不能与其他 .
--mirror 不是将每个 ref 命名为 push,而是指定将 refs/ 下的所有 ref(包括但不限于 refs/heads/、refs/remotes/ 和 refs/tags/)镜像到远程存储库。新创建的本地 refs 将被推送到远程端,本地更新的 refs 将在远程端强制更新,删除的 refs 将从远程端删除。如果设置了配置选项 remote..mirror,则这是默认设置。
回答by kazerm
git clone --mirror [email protected]:username/repo-name.git
git remote add gitlab ssh://[email protected]/username/repo.git
git push -f --tags gitlab refs/heads/*:refs/heads/*
It is better to do it over ssh, the https might won't work
最好通过 ssh 来完成,https 可能不起作用
回答by JBarros35
Gitlab is a little bit bugged on this feature. You can lose a lot of time doing troubleshooting specially if your project is any big.
Gitlab 在这个特性上有点问题。如果您的项目很大,您可能会浪费大量时间进行故障排除。
The best solution would be using the create/import tool, do not forget put your user name and password, otherwise it won't import anything at all.
最好的解决方案是使用创建/导入工具,不要忘记输入您的用户名和密码,否则它根本不会导入任何内容。
Follow my screenshots
按照我的截图