在 GitLab 中导入一个 Linux 仓库(无论是本地已有仓库、其他 Git 服务,还是 Linux 内核类仓库),常见有以下几种方式。下面按 最常用 → 进阶 给你详细说明。
适用于:
https://github.com/torvalds/linux.git
✅ GitLab 会自动克隆整个仓库(包括所有分支和提交历史)
⚠️ 注意:
假设项目地址为:
git@gitlab.com:yourname/linux.git
cd linux
git remote -v # 查看当前远程
git remote add gitlab git@gitlab.com:yourname/linux.git
git push gitlab --all
git push gitlab --tags
✅ 完成后,GitLab 中即可看到完整 Linux 仓库
如果不需要完整 Linux 仓库:
git clone --single-branch --branch master \
https://github.com/torvalds/linux.git linux-master
然后推送到 GitLab。
⚠️ Linux 仓库过大,可能失败,不推荐
适合自动化或 CI/CD:
curl --request POST \
--header "PRIVATE-TOKEN: <your_token>" \
--data "url=https://github.com/torvalds/linux.git" \
https://gitlab.com/api/v4/projects
✅ 解决方案:
git branch -a
git checkout -b master origin/master
~/.ssh/id_rsa 已添加| 场景 | 推荐方式 |
|---|---|
| 小仓库 | GitLab Web 导入 |
| Linux / 大型仓库 | ✅ 本地 clone + push |
| 只需某版本 | --single-branch |
| 自动化 | GitLab API |
如果你愿意,可以告诉我:
我可以给你更精确的方案(包括镜像加速、浅克隆等)。