【问题标题】:GIT clone and first GIT push issueGIT 克隆和第一个 GIT 推送问题
【发布时间】:2012-02-20 21:11:29
【问题描述】:

我有两个问题。我有 Ubuntu 10.10 并且我已经安装了带有 gitolite 的 git 服务器 工具。一切都很好。 gitolite 的 gl-setup 命令创建了 2 个存储库: gitolite-admin 和测试。

1) 问题 1

我的默认 gitolite 管理员用户名为“git”并且已经创建。

首先,我必须克隆 gitolite-admin 存储库,对 conf/gitolite.conf 进行一些更改以添加一些新存储库和一个新用户(我添加了 root 用户,我之前创建了私钥/公钥并将公钥添加到 keydir 文件夹),然后我必须添加/提交并将更改推送回来。3

信息:我的 ~git/.ssh/authorized_keys 文件很好,从 command= 开始并且只有一个值 - 我首先创建的 git 用户的公钥。

没用:

git@vs1:~/$ git clone git@<<SERVER_IP>>:gitolite-admin.git
Initialized empty Git repository in /home/git/ga/gitolite-admin/.git/
git@<<SERVER_IP>>'s password:
fatal: 'gitolite-admin.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

工作:

touch ~/.ssh/config

内容:

host gitolite
     user git
     hostname <<SERVER_IP>>
     identityfile ~/.ssh/git.pub

git@vs1:~/$ git clone gitolite:gitolite-admin
Initialized empty Git repository in /home/git/ga/gitolite-admin/.git/
Enter passphrase for key '/home/git/.ssh/git.pub':
Enter passphrase for key '/home/git/.ssh/git.pub':
Enter passphrase for key '/home/git/.ssh/git.pub':
git@89.35.160.243's password:
remote: Counting objects: 23, done.
remote: Compressing objects: 100% (18/18), done.
remote: Total 23 (delta 4), reused 0 (delta 0)
Receiving objects: 100% (23/23), done.
Resolving deltas: 100% (4/4), done.

为什么我在第一个变体中根本没有工作?所有教程都说它应该可以正常工作。我必须使用第二个变体在 ~/.ssh/config 文件中创建该主机配置。这有点令人沮丧。 repo 路径是 /home/git/repositories,ssh 是默认端口 22。

2) 问题 2

在同一台服务器上使用 root 用户,我在 /var/www/example.com/www 中创建了一个空文件夹。我运行了 git init,然后添加了一个文件 (.gitignore),运行了 git add -A 和 git commit -m "..."。

然后我为原点创建了远程路径:

git remote add origin git@<<SERVER_IP>>:myrepo.git

我运行了 git push origin master,这就是我得到的结果:

fatal: 'myrepo.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

我尝试了各种改变,例如将整个路径放入存储库(即使我没有看到任何地方,所以它不正确)并且我得到了:

Counting objects: 3, done.
Writing objects: 100% (3/3), 243 bytes, done.
Total 3 (delta 0), reused 0 (delta 0)
remote: ENV GL_RC not set
remote: BEGIN failed--compilation aborted at hooks/update line 20.
remote: error: hook declined to update refs/heads/master
To git@<<SERVER_IP>>:/home/git/repositories/myrepo.git
 ! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'git@<<SERVER_IP>>:/home/git/repositories/myrepo.git'

我做错了什么?这令人沮丧,因为对于这样的基本任务,我遇到了这种不寻常的困难。我对 SVN 有很好的经验,这些是第一次使用 GIT。

提前感谢您的帮助!

【问题讨论】:

    标签: git gitolite git-clone git-remote


    【解决方案1】:

    注意 1/:如果 identityfile 是默认名称(id_rsa.pubid_rsa),这可能会起作用。既然不是这样,config 文件是强制性的。

    注意 2/ 你已经创建了一个 git repo,但是你让 gitolite 知道了吗?
    should declare the new repo in the config file of the gitolite-admin repo

    如果您以root 身份通过 ssh 推送,则意味着用户拥有自己的 ~/.ssh/id_rsa(.pub) 密钥,并且这些密钥已为 Gitolite 注册。

    repo 路径注意事项:永远不要使用 repo 的完整本地路径作为推/拉地址:这将完全绕过 Gitolite。


    一个gazillon cmets后来,似乎:

    • 所有远程地址都应该以 git@somehostname:arepo.git 开头:您希望您的用户在 somehostname 上执行 git 命令为 'git'(负责git 和 gitolite)。
      这意味着'myuser'的公钥需要在somehostname:~git/.ssh/authorized_keys上注册

    • 任何时候 ssh 连接不符合您的要求,您可以从查看 ssh debugging tips 开始。
      例如:ssh -vvv git:somehostname 可以很好地说明正在发生的事情

    • 如果您想避免使用config 文件,那么您需要为这些公钥/私钥使用标准 命名约定(~myuser/.ssh/id_rsa~myuser/.ssh/id_rsa.pub

    【讨论】:

    • 1) 好的,但这很奇怪,所有教程(几乎)甚至他们的文档都没有提到为用户 git 创建 ~/.ssh/config 文件的必要性。现在我清理了所有安装并重新安装了所有内容。我重新创建了没有密码的用户“git”,因为我认为这没关系,因为我们使用私钥/公钥登录到 ssh(并且还使用该 ~/.ssh/authorized_keys 文件)。现在,当我尝试克隆 gitolite-admin 存储库时,如果出现尾巴,因为它一直要求我输入密码(而不是使用公钥)。
    • 2) 是的,repo 是之前创建的,它在 repositories 文件夹中可用,并且用户 root 已添加到具有 RW+ 权限的 repos。
    • @ValentinTudor 1) 应该意味着找不到 ssh 密钥(错误的主页、错误的路径或错误的名称):请参阅 sitaramc.github.com/gitolite/sts.html
    • @ValentinTudor 2) 错误消息 (fatal: 'myrepo.git' does not appear to be a git repository) 意味着您的 pubkey(对于 root)正在绕过 gitolite 并直接进入 shell(再次 sitaramc.github.com/gitolite/…
    • 感谢您的回答! 1)我通过在用户“git”上重新创建 ~/.ssh/config 文件解决了这个问题,并且完美地完成了克隆和所有工作(我必须使用主机“gitolite”并且只使用 git clone gitolite:gitolite-admin 语法或使用“somehostname”并仅使用 git clone git@somehostname:gitolite-admin。我想这应该是它的工作方式。
    猜你喜欢
    • 2011-05-11
    • 2010-11-20
    • 2011-03-08
    • 2013-10-03
    • 1970-01-01
    • 2021-06-03
    • 2022-01-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多