When I git clone : fatal: does not appear to be a git repository

Viewed 2108

Why I always got "fatal: does not appear to be a git repository" when I use git push,show,fetch,clone.

I use repo to be my bare repository.

git remote add origin user@dev.com:/home/administration/repo
git push origin master
fatal: '/home/administration/repo' does not appear to be a git repository
fatal: Could not read from remote repository.

I have tried many pattern with my remote url.

like

user@dev.com/home/administration/repo
user@dev.com//home/administration/repo
ssh://user@dev.com/home/administration/repo

However,all of the result were the same.

Steps:

-Server(user@dev.com/home/administration/)
    $ mkdir repo
    $ cd repo
    $ git init --bare
    Initialized empty Git repository in /home/administration/repo/
    $ ls -a
    .  ..  branches  config  description  HEAD  hooks  info  objects  refs
-local
    $ git clone user@dev.com:/home/administration/repo
    warning: You appear to have cloned an empty repository.(repo directory has been created at local)
    $ cd repo
    $ git remote add origin user@dev.com:/home/administration/repo
    $ git remote -v
    origin  user@dev.com:/home/administration/repo (fetch)
    origin  user@dev.com:/home/administration/repo (push)

I just remove my .git directory that was created by vsCode at local.

Then it works.

I can clone the repo.

Howerver,I still can't push by vsCode.

When I use vsCode push,it returns

Permission denied, please try again.

Permission denied, please try again.

user@dev.com: Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).

fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

I guess it's the password problem with ssh,but I can't type password in vsCode.

I try @VonC's method

My OS is Win10

-local
    > ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/username/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/username/.ssh/id_rsa_ubuntu.
    Your public key has been saved in /home/username/.ssh/id_rsa_ubuntu.pub.
    The key fingerprint is:
    SHA256:nNnQckFbuegUs4WD3y+7YqwCaDhfUlX2J17jxF7X3FU xenby@demo.com
    The key's randomart image is:
    +---[RSA 2048]----+
    |       .o++ ..  E|
    |      .  *o+.  ..|
    |     .  = *+ o ..|
    |    .  . Ooo+ * +|
    | . o    Soo..B o.|
    |o + o     . ..o  |
    | + o .   .  . .  |
    |  .   .   +  o   |
    |       ..o .o.   |
    +----[SHA256]-----+
    > cp C:\Users\UserName\.ssh\id_rsa.pub C:\Users\UserName\authorized_keys
-Server
    > mkdir ~/.ssh
-local(Windows doesn't exist "ssh-copy-id",so I use scp)
    > scp authorized_keys user@dev.com:~/.ssh
    user@dev.com's password:
-Server
    > chmod 700 ~/.ssh
    > chmod 600 ~/.ssh/authorized_keys

After I did these things,I still need to key password when I use ssh user@dev.com....

What is my problem?

2 Answers

As mentioned in the VSCode SSH troubleshooting page, if your private key is passphrase-protected, you should have an ssh-agent started first.

But if you can push manually, but have to enter the user password (as opposed to the key passphrase), that actually means the public key was not added to ~user/.ssh/authorized_keys.

That should not be your issue if you can clone. And if you can clone, you don't have to do a git remote add origin ...: the remote origin is already set during the clone.

Create a local GIT Repository in your local file system

From the directory where you want to host your remote repoistory location

  • git init --bare repoName.git creates a repo called as repoName.git that can be used as a remote along with all required files inside

From the directory where you can want to hook up to the remote repository, having a valid GIT enabled project code

  • git remote add origin "/path/to/my/repoName.git" add the path to the above create remote repository
  • git remote -v to check the remote localtion path is correct
  • git push --set-upstream origin master to push the code and set the upsteam as the branch master
  • git push origin all later push syntax

To clone this repository in a new directory

From the new directory

  • git clone "path/to/my/repoName.git" newDirName clones the repository into a new Directory
Related