将现有本地 Git 主存储库导入 Gitlab:Git 用户访问问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25012968/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 02:16:45  来源:igfitidea点击:

Import Existing Local Git Master Repo into Gitlab: Git user Access Issues

gitgitlab

提问by rhand

I have a git master branch on my test server under testvps.subdomain.domain.com:~public_html/domain.com/ZendSkeletonApplication/. I have Gitlab CentOS rpm up and running on that same server now at http://testvps.subdomain.domain.com:8888

我的测试服务器上有一个 git master 分支testvps.subdomain.domain.com:~public_html/domain.com/ZendSkeletonApplication/。我现在在同一台服务器上启动并运行 Gitlab CentOS rpm,网址为http://testvps.subdomain.domain.com:8888

Import Local Master Repo into Gitlab

将本地主仓库导入 Gitlab

I need to import this existing localrepository into Gitlab (See earlier question on cloning the repo herewith ssh. ) on the same test server. This repo is the master branch NOT the original branch origin which is ZendApplication on Github. For passworded access Gitlab suggested a link like https://username:[email protected]/company/project.gitDocumentation mentions to copy bare repos to /home/git/

我需要导入这个现有的本地库到Gitlab(参见克隆回购较早前的问题在这里使用ssh)相同的测试服务器上。这个 repo 是 master 分支,而不是 Github 上 ZendApplication 的原始分支起源。对于密码访问,Gitlab 建议使用类似https://username:[email protected]/company/project.git文档提及的链接将裸存储库复制到 /home/git/

What is the best approach?

最好的方法是什么?

The user git has been added only somehow the home directory was not created I guess that has to be done manually - see link here. Not sure if this is needed for proper imports though. And this being a master branch would require a different approach to import the existing git repository with 20+ commits it seems. Perhaps I should make the master a new origin? How should I go about doing this?

用户 git 只是以某种方式添加了主目录,我想这必须手动完成 - 请参阅此处的链接。不过,不确定是否需要正确导入。作为一个主分支,它似乎需要一种不同的方法来导入具有 20 多个提交的现有 git 存储库。或许我应该让大师成为一个新的起源?我该怎么做呢?

Update

更新

I have added gitlab .git repo as new remote.

我已经添加了 gitlab .git repo 作为新的远程。

git remote set-url origin [email protected]:root/repo.git
git remote -v
origin  [email protected]:root/repo.git (fetch)
origin  [email protected]:root/repo.git (push)

When I try to push to it I get a request for the password for the git user

当我尝试推送它时,我收到了 git 用户密码的请求

git push -u origin master
[email protected]'s password: 

which is not supposed to be needed nor do I have it. How can I fix this?

这不应该是需要的,我也没有。我怎样才能解决这个问题?

PS sudo -u git -H bundle exec rake gitlab:check RAILS_ENV=productiondoes not work as it mentions bundle as command is missing

PSsudo -u git -H bundle exec rake gitlab:check RAILS_ENV=production不起作用,因为它提到 bundle as command is missing

采纳答案by rhand

With the help of another server admin I worked things out. I need to generate and add a ssh key as described here http://www.codeproject.com/Articles/674637/How-to-passwordless-sshfor example. Somehow during the installation of Gitlab this was not taken care of. So a key was generated and added to authorized keys:

在另一位服务器管理员的帮助下,我解决了问题。例如,我需要按照http://www.codeproject.com/Articles/674637/How-to-passwordless-ssh中的说明生成并添加 ssh 密钥。不知何故,在安装 Gitlab 的过程中没有考虑到这一点。因此生成了一个密钥并将其添加到授权密钥中:

ssh-keygen -t rsa
Generating public/private rsa key pair.
//store in home directory of user and then copy to authorized keys at destination
cat /user/.ssh/id_rsa.pub >>  /var/opt/gitlab/.ssh/authorized_keys

Also, the path to the Gitlab repo was not correct. All repos are located here: /var/opt/gitlab/git-data/repositories/and my repo was under my user - jasper for now - and thus [email protected]:/var/opt/gitlab/git-data/repositories/jasper/repo.git

此外,Gitlab 存储库的路径不正确。所有存储库都位于此处:/var/opt/gitlab/git-data/repositories/我的存储库在我的用户之下 - 现在是 jasper - 因此[email protected]:/var/opt/gitlab/git-data/repositories/jasper/repo.git

回答by slonik

ONCE YOU HAVE SORTED YOUR USER ACCESS ISSUES:

对用户访问问题进行排序后:

  1. Create a new project on GitLab with the same name as your local project.
  2. On your local do: git remote add origin git@repo-url:projectpath/projectname.git
  3. git push
  1. 在 GitLab 上创建一个与本地项目同名的新项目。
  2. 在你当地做: git remote add origin git@repo-url:projectpath/projectname.git
  3. git push