在 Debian 上部署的 GitLab 中导入项目,常见有几种方式。下面按使用场景给你说明。
GitLab 支持:
例如导入 Git URL:
https://github.com/user/repo.git
在 Debian 上已有项目:
cd /path/to/your/project
git init
git add .
git commit -m "init"
在 GitLab 创建空项目后:
git remote add origin git@gitlab.example.com:group/project.git
git push -u origin master
(或 main,取决于 GitLab 版本)
如果你是 GitLab 服务器管理员:
/var/opt/gitlab/git-data/repositories/
sudo chown -R git:git /var/opt/gitlab/git-data/repositories/your-group
⚠️ 不推荐新手使用,容易权限出错。
如果你是从另一台 GitLab 迁移:
gitlab-rake gitlab:backup:restore BACKUP=1234567890
适用于:
git clone --bare old_repo.git
cd old_repo.git
git push --mirror git@gitlab.example.com:group/new_repo.git
适合保留:
Permission denied (publickey)
解决:
ssh -T git@gitlab.example.com 测试修改:
vim ~/.ssh/config
Host gitlab.example.com
Port 2222
| 场景 | 推荐方式 |
|---|---|
| 新项目 | Web 创建 + git push |
| 已有 Git 仓库 | git remote + push |
| 迁移 GitLab | 备份恢复 |
| GitHub 项目 | Web 导入 |
如果你能说明:
我可以给你更精确的命令。