-->

Git error: “Please make sure you have the correct

2019-03-08 22:41发布

问题:

I am using TortoiseGit on Windows. When I am trying to Clone from the context menu of the standard Windows Explorer, I get this error:

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

More precisely, the snapshot of terminal is the following:

git.exe clone --progress -v "git@arobotdev:\git\AlfaRobot.git" "C:\Work\AlfaRobot"

Cloning into 'C:\Work\AlfaRobot'...
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
fatal: Could not read from remote repository.

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

git did not exit cleanly (exit code 128) (21450 ms @ 19.09.2014 10:36:58)

What should I do to make git work properly ?

回答1:

Your git URL might have changed. Change the URL in the local directory by using the following command

git remote set-url origin git@XXXXXXXXXXXX


回答2:

That problem might be having with your ssh-agent, your ssh key hasn't been added with ssh-agent.You have to apply following steps using your terminal:-

  1. $ eval "$(ssh-agent -s)"

    Agent pid 5867

  2. $ ssh-add

    Enter passphrase for /home/you/.ssh/id_rsa: [] Identity added: /home/you/.ssh/id_rsa (/home/you/.ssh/id_rsa)

then it will work..cheers J.



回答3:

For me it was because of no SSH key on the machine. Check the SSH key locally:

$ cat ~/.ssh/id_rsa.pub

This is your SSH key. Add it to your SSH keys in the repository.
In gitlab go to

profile settings -> SSH Keys

and add the key



回答4:

Try to use HTTPS instead SSH with taking close url from GIT, it work for me. and then take from of that url, by gitbase or any other git client.



回答5:

You are trying to clone the repository over ssh: git@arobotdev..., and your SSH keys are not properly set on server. There are multiple reasons to this:

  1. Your public key might not be saved in authorized_keys file of user git
  2. If 1 is not true the Your private key is not saved in .ssh/ folder of your HOMEDIR.
  3. Permissions are not properly set

If all 3 above are untrue then my only conclusion can be to try: git@arobotdev:AlfaRobot.git Assuming AlfaRobot.git is in HOMEDIR of git user and not inside a folder called git which resides in HOMEDIR of user git.



回答6:

The rsa.pub (i.e. public key generated), needs to be added on the github>> settings>>ssh keys page. Check that, you have not added this public key in the repository-settings >> deployment keys. If so, remove the entry from here and add to the first place mentioned.

Setup of the pub-private keys in detail.

It will work hence!



回答7:

Here is how I solve this issue. I was using Babun(mintty.exe) on Win7/10. When I have tried many solutions mentioned above, and none of them works. I realized maybe I just used wrong ssh agent... So I run echo $GIT_SSH to find out, it shows the path to Plink.exe. What I actually expected is OpenSSH.

So, I add following one-liner to ~/.zshrc file

Note 1: You can execute it in babun directly also
Note 2: You if you use bash then the config file is .bashrc

export GIT_SSH=$(which ssh)

And It works!



回答8:

add these lines to your .get/config file (thanks to @kovshenin answer Git Pull: Change Authentication) :

[credential]
    helper = wincred


回答9:

Try https instead of ssh. Choose the https option from project home page where you copy the clone url from.



回答10:

An alternative problem may be your internet connection. Obvious maybe, but took me a few minutes to figure out my wifi was down :)



回答11:

  1. The first thing you may want to confirm is the internet connection. Though, internet issues mostly will say that the repo cannot be accessed.

  2. Ensure you have set up ssh both locally and on your github. See how

  3. Ensure you are using the ssh git remote. If you had cloned the https, just set the url to the ssh url, with this git command git remote set-url origin git@github.com:your-username/your-repo-name.git

  4. If you have set up ssh properly but it just stopped working, do the following:

    • eval "$(ssh-agent -s)"
    • ssh-add

    If you are still having the issue, check to ensure that you have not deleted the ssh from your github. In a case where the ssh has been deleted from github, you can add it back. Use pbcopy < ~/.ssh/id_rsa.pub to copy the ssh key and then go to your github ssh setting and add it.

I will recommend you always use ssh. For most teams I've worked with, you can't access the repo (which are mostly private) except you use ssh. For a beginner, it may appear to be harder but later you'll find it quite easier and more secured.



回答12:

Like other answers, use https instead of ssh was the solution.

I post an answer to give a concrete example of a possible solution. I solved this issue with bitbucket when I changed remote url to HTTPS with this command line:

git remote set-url origin <bitbucket_URL>

After that, I could push the content to the repository with this command:

git push -u origin --all

And then I could also use Sourcetree



回答13:

Strangely I only received this error in 1 of my many repos.

My issue was after installing the new GitHub Desktop for Windows where the previous old GitHub for Win kept keys in ~/.ssh/github_rsa and ~/.ssh/github_rsa.pub where as the new GitHub for Win expects it in ~/.ssh/id_rsa so the solution was just renaming the existing private and public keys:

~/.ssh/github_rsa -> ~/.ssh/id_rsa
~/.ssh/github_rsa.pub -> ~/.ssh/id_rsa.pub

After which let me access the repo again without issue.



回答14:

This can also happen if you are connecting to your git repository through a VPN. Make sure that you are connected to the VPN which is used to access the resources of your organization.