Background
I needed to take a quick look at a GitHub repository.
I launched a command shell and issued “git clone” against the repository.
Git Command
Here is the syntax and sample for the git clone command.
Git Clone
Syntax
git clone git@github.com:[organization]/[repository].git
Text
git clone git@github.com:labOrg/sample.git
Error
Error Message
Unfortunately, we encountered an error.
The error is:-
Image
Text
git@github.com: Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Troubleshooting
Outline
- Review Command
- What does the command do?
- What application protocol are we using?
Review Command
What does the command do?
Please review the command.
In our case git clone.
Git Clone copies a remote repository unto our local machine.
Network Application Protocol?
To communicate with a git server we can utilize HTTP or SSH.
Remediation
Outline
- SSH / HTTP / GitHub CLI
- Analysis
SSH / HTTPS / GitHub CLI
Retrieve Git Clone Command
Steps
Let us access GitHub and get a copy of the git clone command for our targeted repository.
To get the git clone command, please do the following:-
- Launch a web browser
- GitHub Repository
- Access GitHub web site
- Access your Account by passing along your credentials ( username & password )
- Access your targeted repository
- Within the Targeted Repository
- Access the Code Tab
- Click the Code button
- The various options for getting the Repository Code is displayed
- Here are the options:-
- Clone Command
- Clone HTTP
- Clone SSH
- Clone GitHub CLI
- Open with GitHub Desktop
- Download Zip
- Clone Command
Image
Sample
If we click on each GitHub Clone Option, we will be offered the git clone command that we should issue to download the targeted repository.
- HTTPS
- https://github.com/labOrg/sample1.git
- SSH
- git@github.com:labOrg/sample1.git
- Git Hub CLI
- gh repo clone labOrg/sample1
Analysis
The machine we are using has not been configured to communicate with our GitHub Server using SSH.
To use SSH we will need to create SSH keys on the client workstation and upload those keys on our GitHub Server.
We will thus draw back and use HTTP.
Attempt Git Clone – HTTPS Protocol
Command
Here is the syntax and sample for the “git clone” command.
Syntax
git clone https://github.com/[organization]/[repository].git
Sample
git clone https://github.com/labOrg/sample1.git
Output
Output Text
>git clone https://github.com/DanielAdeniji/sample1.git Cloning into 'sample1'... info: please complete authentication in your browser... remote: Enumerating objects: 55, done. remote: Counting objects: 100% (55/55), done. remote: Compressing objects: 100% (32/32), done. remote: Total 55 (delta 12), reused 49 (delta 6), pack-reused 0 Receiving objects: 100% (55/55), 10.16 KiB | 1.27 MiB/s, done. Resolving deltas: 100% (12/12), done.
Image
Summary
Needlessly, took a lot of time and ink to explain an error message.
The error read:-
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
I really wish the error message was a bit more concise.
I like developers who take the time to give more verbose error messages.
I already know that the machine I am on is a virgin and it is not setup for git.
But pity that your man, who is a bit green, yet wants to start using the command shell more.