Git Clone Failure

git, git-clone

Solution

The first problem is that you can't login to the server:

Cloning into 'my_test_repo'...
Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

You need to get this command working first:

ssh ec2-user@ec2-54-81-229-189.compute-1.amazonaws.com

This problem has nothing to do with Git, you need to get `ssh` working with public key authentication.

The second problem is that the path to your repository is probably wrong. If your repository on the server is in the `.git` directory inside `/home/ec2-user/my_test_repo`, then the URL would be:

git clone ssh://ec2-user@ec2-54-81-229-189.compute-1.amazonaws.com/home/ec2-user/my_test_repo/.git

Notice the end part is `my_test_repo/.git`, because it should correspond to the filesystem path of the directory containing a Git repository. A Git repository contains files like `HEAD`, `config`, and directories like `objects`, `refs`, `hooks`, and some others.

As such, it looks like `my_test_repo` is a so-called working tree. If you clone from `my_test_repo/.git`, you won't be able to push to it, because git doesn't allow pushing to repositories with working tree. It only allows pushing to a so-called bare repository, without a working tree. You can create a bare repository from your existing non-bare repository with these commands:

git clone --bare my_test_repo my_test_repo.git

After you do this, your original URL should work, because now the path to the Git repository is really `my_test_repo.git`, instead of `my_test_repo/.git`. You don't need the `my_test_repo` working tree anymore, you can delete it.

Finally, you could simplify the repository URL like this:

git clone ec2-user@ec2-54-81-229-189.compute-1.amazonaws.com:my_test_repo.git

Problem

I have a Linux-based Amazon AMI which houses a Git repository. I want to `git clone` that repository to my local OSX machine (which also has Git installed). The repository lives on the Amazon box at `/home/ec2-user/my_test_repo`. Inside of the `my_test_repo` directory is the `.git` directory. On my OSX machine I can successfully SSH to the machine hosting the repo as `ec2-user` and I can execute lots of bash commands. So, I know SSH works. However, the following command doesn't work when I execute it from my OSX machine: ``` git clone ssh://ec2-user@ec2-54-81-229-189.compute-1.amazonaws.com/home/ec2-user/my_test_repo.git ``` I get the following error message: ``` Cloning into 'my_test_repo'... Permission denied (publickey,gssapi-keyex,gssapi-with-mic). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists. ``` Any ideas what I'm doing wrong here?

Original source