Help us understand the problem. What is going on with this article?

gitlabへのpush時に「does not appear to be a git repository」と表示されるときの対策

More than 5 years have passed since last update.

現象

gitlabへのpush時に以下のエラーが出てpushできない。
gitlabのバージョン:6-3-stable

$ git push -u origin master
fatal: 'username/test01.git' does not appear to be a git repository
fatal: The remote end hung up unexpectedly

この時のoriginは以下のとおり。

git@gitlab.cadence:username/test01.git

以下のようにすればpushできるが、変なのでrepositoriesなしでもpushできるようにしたい。

git@gitlab.cadence:repositories/username/test01.git

原因

以下のサイトによればgitlabの設定前に公開鍵が~/.ssh/authorized_keysに設定されていると発生する。
確かにAnsibleでGiltabを構築するでは公開鍵を登録していた。。

gitlab public wiki - Could not read from remote repository

解決策

gitlab用の公開鍵・秘密鍵ペアを作成する。

  • 公開鍵・秘密鍵を作成
$ ssh-keygen 
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/xxx/.ssh/id_rsa): /Users/xxx/.ssh/id_rsa_gitlab
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/xxx/.ssh/id_rsa_gitlab.
Your public key has been saved in /Users/xxx/.ssh/id_rsa_gitlab.pub.
The key fingerprint is:
xxxx
The key's randomart image is:
xxxx
  • gitlabへの公開鍵の登録

    Profile settings > SSH Keys > Add SSH Keysで登録する。

  • ~/.ssh/configの編集
    鍵を指定してアクセスするように~/.ssh/configを編集する。

~/.ssh/config
Host gitlab.cadence
  User git
  Port 22
  Hostname gitlab.cadence
  IdentityFile ~/.ssh/id_rsa_gitlab
  • git設定ファイルの編集 リポジトリ毎などの設定に合わせて編集する。
[remote "origin"]
    url = git@gitlab.cadence:username/test01.git
    fetch = +refs/heads/*:refs/remotes/origin/*

もしくは以下のコマンドでOK(というかこっちの方がわかりやすい)

$ git remote add origin git@gitlab.cadence:username/test01.git

以上

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした