I am trying to set git up with http://danielmiessler.com/study/git/#website to manage my site.
I have gotten to the last step in the instructions: git push website +master:refs/heads/master
I am working using the git ming32 command line in win7
$ git push website +master:refs/heads/master
Bill@***.com's password:
Connection closed by 198.91.80.3
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
One problem here may be that the program is looking for Bill@***.com. when I connect via ssh to my site I have a different username( lets say ‘abc’). so maybe this should be abc@***.com. If so I don’t know how to change this or if I can push under an alias
mudri
7583 silver badges16 bronze badges
asked Nov 22, 2012 at 9:18
user1592380user1592380
34.3k93 gold badges284 silver badges515 bronze badges
12
Your ssh key most likely had been removed from ssh agent
ssh-add ~/.ssh/id_rsa
where id_rsa is a ssh key associated with git repo
Update
You may get Could not open a connection to your authentication agent.
error to resolve that you need to start the agent first by:
eval `ssh-agent -s`
Abdul Baig
3,6833 gold badges21 silver badges48 bronze badges
answered Oct 12, 2016 at 22:49
13
I was facing same issue a while ago…
my .git/config had
url = git@github.com:manishnakar/polymer-demo.git
I replaced it with
url = https://github.com/manishnakar/polymer-demo.git
and it works now:)
answered Dec 4, 2015 at 5:38
Manish NakarManish Nakar
4,2861 gold badge18 silver badges13 bronze badges
11
You can specify the username that SSH should send to the remote system as part of your remote’s URL. Put the username, followed by an @
, before the remote hostname.
git remote set-url website abc@***.com:path/to/repo
answered Nov 22, 2012 at 9:24
rob mayoffrob mayoff
376k67 gold badges797 silver badges849 bronze badges
9
Make sure you have correct url in .git/config
url = git@github.com:username/repo.git
If it’s your first push, you’ll need to set up correct upstream
$ git push -u origin master
You can check which key is used by:
$ ssh -vvv git@github.com
The reply should contain something like this:
debug1: Next authentication method: publickey
debug1: Offering RSA public key: ~/.ssh/id_rsa
...
You've successfully authenticated, but GitHub does not provide shell access.
Also it’s possible to define rules for ssh in ~/.ssh/config
, e.g. based on aliases:
Host github
HostName github.com
User git
IdentityFile "~/.ssh/id_rsa"
Host git
HostName github.com
User git
IdentityFile "~/.ssh/some_other_id"
You can set connect to different ports, use different username etc. for each alias.
answered Dec 21, 2013 at 0:51
TombartTombart
30.6k16 gold badges123 silver badges137 bronze badges
9
I had a wrong ssh private key for Bitbucket along with the right one in ssh agent.
Deleted all keys first
ssh-add -D
Then added just the right key.
ssh-add ~/.ssh/id_rsa
answered Mar 20, 2020 at 21:55
ForeeverForeever
7,1299 gold badges53 silver badges56 bronze badges
4
Make sure ssh-agent is running by executing the following command on your terminal:
eval $(ssh-agent -s)
Source: Github documentation
answered Oct 19, 2015 at 20:05
user3362907user3362907
2993 silver badges3 bronze badges
3
This is usually caused due to the SSH key is not matching with the remote.
Solutions:
-
Go to terminal and type the following command (Mac, Linux) replace with your email id.
ssh-keygen -t rsa -C «you@email.com»
-
Copy the generated key using following command starting from word ssh.
cat ~/.ssh/id_rsa.pub
- Paste it in github, bitbucket or gitlab respective of your remote.
- Save it.
answered Sep 27, 2015 at 11:45
0
Try removing the GIT_SSH environment variable with unset GIT_SSH
. This was the cause of my problem.
CB.
5321 gold badge4 silver badges11 bronze badges
answered Jul 30, 2014 at 17:25
6
I had the same problem.
This error means that you have not specified your remote URL location upon which your code will push.
You can set remote URL by 2 (mainly) ways:
-
Specify remote URL via executing command on Git Bash.
-
Navigate to your project directory
-
Open Git Bash
-
Execute command:
git remote set-url origin <https://abc.xyz/USERNAME/REPOSITORY.git>
-
-
Mention remote URL direct in config file
-
Navigate to your project directory
-
Move to .git folder
-
Open config file in text editor
-
Copy and paste below lines
[remote "origin"]
url = https://abc.xyz/USERNAME/REPOSITORY.git
fetch = +refs/heads/*:refs/remotes/origin/*
-
For more detailed info visit this link.
answered Apr 18, 2017 at 15:51
Pratik PatelPratik Patel
2,2193 gold badges23 silver badges30 bronze badges
1
Another workaround:
Sometimes this happens to me because of network problems. I don’t understand the root problem fully, but switching to a different sub-network or using VPN solves it
answered Jun 22, 2015 at 15:07
kip2kip2
6,4834 gold badges55 silver badges72 bronze badges
2
I had the same error.
The solution was following:
I’ve corrected my url in .git/config
.
Just copied that from HTTPS clone URL. That would be something like that:
url = https://github.com/*your*git*name*/*your*git*app*.git
It worked.
answered Jan 23, 2015 at 21:05
tan75tan75
1151 silver badge2 bronze badges
3
Pretty straightforward solution that worked for me, see below:-
Problem
$ git clone git@github.com:xxxxx/xxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.
This should also timeout
$ ssh -T git@github.com
ssh: connect to host github.com port 22: Connection timed out
This might work
$ ssh -T -p 443 git@ssh.github.com
Hi xxxx! You've successfully authenticated, but GitHub does not provide shell access.
Override SSH settings
$ vim ~/.ssh/config
# You can also manually open the file and copy/paste the section below
# Add section below to it
Host github.com
Hostname ssh.github.com
Port 443
Then try again
$ ssh -T git@github.com
Hi xxxxx! You've successfully authenticated, but GitHub does not
provide shell access.
Try cloning now (should work)
$ git clone git@github.com:xxxxxx/xxxxx.git my-awesome-proj
Cloning into 'my-awesome-proj'...
remote: Enumerating objects: 15, done.
remote: Counting objects: 100% (15/15), done.
remote: Compressing objects: 100% (14/14), done.
remote: Total 15 (delta 0), reused 15 (delta 0), pack-reused 0
Receiving objects: 100% (15/15), 22.90 KiB | 4.58 MiB/s, done.
Reference: here => Use HTTPS with Port 443
answered Mar 1, 2022 at 14:35
Shuvo AminShuvo Amin
6318 silver badges14 bronze badges
2
After doing some research I’ve finally got solution for this, you have declared a environment variable to plink.exe path. So if you remove that path, reopen the git bash and try cloning through SSH it will work.
Refer to this link
http://sourceforge.net/p/forge/site-support/2959/#204c
answered Oct 1, 2013 at 10:38
If after»git push origin master» command u see the error «could not read from remote repository» then try this out
1.ssh-keygen -t rsa -b 4096 -C "youremail"
2.eval $(ssh-agent -s)
3.ssh-add ~/.ssh/id_rsa
4.clip < ~/.ssh/id_rsa.pub(it copies the ssh key that has got generated)
5.then go to your remote repository on github and goto settings-> SSH and GPG keys ->new SSH key ->enter any title and paste the copied SSH key and save it
6. now give git push origin master
Vega
27.9k27 gold badges96 silver badges103 bronze badges
answered Feb 10, 2018 at 15:44
sushmithasushmitha
791 silver badge2 bronze badges
In your .git/config file
[remote "YOUR_APP_NAME"]
url = git@heroku.com:YOUR_APP_NAME.git
fetch = +refs/heads/*:refs/remotes/YOUR_APP_NAME/*
And simply
git push YOUR_APP_NAME master:master
answered Jul 27, 2013 at 20:20
I had a perfectly fine working git and suddenly I got that error when I tried to push to the master. As I found out, it was because the repository host had problems.
If you using GitHub or Bitbucket you can easily check the status at
https://status.github.com/messages or https://status.bitbucket.org/
answered Mar 2, 2018 at 17:04
AdamAdam
26.1k22 gold badges158 silver badges247 bronze badges
1
If you use Gitlab than you might need to log in and accept Gitlab new terms, before you try to pull or push.
answered May 23, 2018 at 18:52
Marcelo AgimóvelMarcelo Agimóvel
1,6682 gold badges20 silver badges25 bronze badges
2
You need to use HTTPS for Git:
Type this into the Terminal:
$ git remote set-url origin abc@***.com:path/to/httpURLRepo
Then commit:
$ git add .
$ git commit -m "This is the commit message"
answered May 7, 2020 at 18:26
SwiftiSwiftSwiftiSwift
7,58810 gold badges56 silver badges97 bronze badges
1
I have tried everything including generating new key, adding to the GitHub account, editing .ssh/config and .git/config. But still it was giving me the same error.
Then I tried following command and it does work successfully.
ssh-agent bash -c 'ssh-add ~/.ssh/id_rsa; git clone git@github.com:username/repo.git'
answered Mar 1, 2019 at 0:16
2
updated OCT 2020
In most of the case when you have more than one user access the same git server from a same client system, that time git server confused to with access key with the user both users allowed but when you fire command that time its used default user.
ssh -T git@gitlab.com
see which user are activatly you try to push with that user
the simple solution removes the unused user public key from the git server.
then try to git fetch or pull, push it will work for me
answered Oct 13, 2020 at 11:14
Mr CoderMr Coder
5073 silver badges13 bronze badges
In my case I was using an ssh key with a password to authenticate with github. I hadn’t set up pageant properly in Windows (only in cygwin). The missing steps were to point the git_ssh environment variable to plink.exe. Also, you need to get github.com into the plink known_hosts.
plink github.com
y
<then ctrl-c>
Hope this helps!
I sure wish intellij would have given me a more useful error, or better yet asked me to type in the ssh key password.
answered Sep 5, 2016 at 1:22
Jeff HoyeJeff Hoye
5805 silver badges11 bronze badges
user@server:/etc/nginx$ cat .git/config
...
[remote "origin"]
url = git@gitlab.com:user/.git
fetch = +refs/heads/*:refs/remotes/origin/*
...
- Use ssh instead of https.
- To use ssh key in git (add ssh key).
- If you are root, use the ssh key.
$ sudo ssh-keygen
$ cat /root/.ssh/id_rsa.pub
$ git init
$ git add file
$ git commit -m "add first file"
$ git remote add origin git@gitlab.com:user/example.git
$ git push -u origin master
answered Sep 18, 2017 at 0:31
I solved this issue by restarting the terminal (open a new window/tab).
So if you don’t really want/need to understand the underlying problem, test method is worth a try before digging deeper
answered Jan 30, 2019 at 10:46
mraxusmraxus
1,3771 gold badge15 silver badges23 bronze badges
2
I meet the problem just now and fix it by: git config user.email "youremail"
.
update:
The root cause maybe my poor network and poor proxy.
I still don’t know why it happened, but every time has this error, this command works!!!
answered Sep 21, 2019 at 7:35
FakeAlcoholFakeAlcohol
8607 silver badges29 bronze badges
In my case, The bitbucket’s web ssh key setup UI is confusing.
Repository Settings -> Access keys -> Add key : Error
Personal settings -> SSH keys -> Add key : Ok
The public key registration screen is mutually exclusive. You must register the public key only in one place. It seems good to unify them on one screen.
answered Oct 17, 2021 at 2:16
sailfish009sailfish009
2,5611 gold badge24 silver badges31 bronze badges
1
My issue was resolved by using these commands on Windows 11
1. I opened up the Git Bash command and started ssh-agent.
eval "$(ssh-agent -s)" // this command only work in git bash.
2. Added by ssh-key
ssh-keygen -t rsa -b 4096 -C "your_email@example.com" //it must be 4096
ssh-add id_rsa
3. Check properly added or not.
ssh-add -l
4. Uploaded its public key on GitHub as (Authorization key)
cat id_rsa.pub | clip
5. Unset any proxy and GIT_SSH variable
unset GIT_SSH
git config --global --unset http.proxy
git config --global --unset https.proxy
6. Must check github.com should be resolved.
ping github.com
7. Now check Connectivity with Github.
ssh -T git@github.com
Output
The authenticity of host ‘github.com (20.207.73.82)’ can’t be
established. ED25519 key fingerprint is
SHA256:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx This key is not known by
any other names Are you sure you want to continue connecting
(yes/no/[fingerprint])? yes Warning: Permanently added ‘github.com’
(ED25519) to the list of known hosts. Hi MHamzaRajput! You’ve
successfully authenticated, but GitHub does not provide shell access.
answered Sep 2, 2022 at 7:15
M. Hamza RajputM. Hamza Rajput
7,8402 gold badges41 silver badges36 bronze badges
I resolved this issue by change my url
from
https://gitlab.com/{gitlab_user}/project_repo.git
to
https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git
using command
git remote set-url https://{gitlab_user}@gitlab.com/gitlab_user/project_repo.git
answered Dec 12, 2022 at 9:30
Al FahadAl Fahad
2,3785 gold badges28 silver badges37 bronze badges
I was facing the same issue. so here’s the way i resolved the same
Step 1:
create a new ssh key:-
ssh-keygen -t ed25519 -C "your_email@example.com"
Step 2:
copy the ssh key on clipboard :-
pbcopy < ~/.ssh/id_ed25519.pub
Step 3:
now paste copied ssh key to the corresponding git repository
Step 4:
Start the ssh-agent in the background.
$ eval "$(ssh-agent -s)"
> Agent pid 59566
Step 5:
now try accesing the repo
git clone git@github.com:username/repo-name.git
Step 6:
if still you see the issue then check the ssh config file
vim ~/.ssh/config
the content should look like
Host github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519
Step 7:
Add your SSH private key to the ssh-agent and store your passphrase in
the keychain
ssh-add --apple-use-keychain ~/.ssh/id_ed25519
Step 8:
Now try again it should work
git clone git@github.com:username/repo-name.git
answered Aug 15 at 11:06
For my case, I am using Corporate network (without internet connection) in office. In order to pull code from github, I set https proxy in gitbash and then use https instead of ssh to pull code,it works fine. However when comes to push code, the https proxy won’t work. So either switch to Internet network (with internet connection) or set ssh proxy can solve the problem.
answered Jul 8, 2015 at 11:00
wenwenwenwen
1841 silver badge5 bronze badges
Actually I tried a lot of things to make it work on Win7, since changing the SSH exectun fron native to build-it and backwards and the same error.
By chance, i change it to HTTPS in the «.git/config» file as:
[remote "origin"]
url = https://github.com/user_name/repository_name.git
fetch = +refs/heads/*:refs/remotes/origin/*
and it finally worked. So maybe it could work for you as well.
answered Mar 9, 2016 at 22:13
This tutorial shows you the two main origins and solutions to the error, «fatal: could not read from remote repository.» These are:
- Git pushing to non-existing remote URL
- Failing to config SSH keys properly
First, the tutorial briefly takes you through Git remote and creating an SSH connection between Git and GitHub. Next, the tutorial creates the error then shows you how to solve it step by step.
We use GitHub for the demos, but you can still follow along with a different website.
Git remote
Git tracks its connection to GitHub using the git remote
command. For example, you can check the destination URLs using the git remote -v
command.
steve@thisHostname:~/workingDir/pyFiles/.git$ git remote -v
origin https://github.com/Stevealila/Python.git (fetch)
origin https://github.com/Stevealila/Python.git (push)
origin
is an alias for the https://github.com/Stevealila/Python.git
URL. You can modify or update it.
The https
part shows that the connection is via HTTPs, not SSH. github.com
is the website, while Python
is the name of the remote repository. (fetch)
or (push)
means we can get (clone or pull) or send (push) data through the remote URL, respectively.
Since getting or sending data to a remote may occur through multiple branches, you need to specify the (default is main) branch after the origin
part.
git push origin main
You may ignore the origin main
part if the remote only has one branch and the branch is checked out during the git push
process.
git push
The key takeaway is that Git must know the path to fetching from or pushing changes to a remote repository. Otherwise, it may throw the error fatal: could not read from remote repository.
Before diving into practical examples, let me show you another common origin of the error.
ALSO READ: git HEAD~ vs HEAD^ vs HEAD@{} Explained with Examples
SSH Connection
Secure Shell (SSH) ensures two remote computers can connect and share data securely. In this case, your (local) computer and (remote) GitHub server want to share code.
But instead of asking you to input your username and password every time you want to push to the remote repository, SSH automatically completes the connection because the computers already remember each other after the initial connection.
So, you probably get the message, «fatal: could not read from remote repository.» because the remote machine cannot remember (authenticate) your local computer.
But how do you know if an SSH connection exists?
First, check the existence of the keys in the ~/.ssh
folder of your local computer.
ls ~/.ssh
Better yet, you can generate a new one.
ssh-keygen -t ed25519 -C "<your GitHub email address>"
ssh-keygen
is the command to generate a key.
The -t
option specifies the type of encryption used to generate the key. I have used ed25519
algorithm. You can also try out rsa
algorithm.
The -C
option stands for comment.
Running the command outputs an SSH key pair: public and private. The public key ends in a .pub
extension, while the private key lacks an extension.
You should inform your computer’s SSH agent about the new keys. The agent is the wallet that safely stores your various SSH keys. You can start up the SSH agent using the following commands.
eval "$(ssh-agent -s)"
Next, store your private key in the agent’s wallet using the following commands.
ssh-add ~/.ssh/id_ed25519
id_ed25519
is the private key we generated earlier. Its full path is ~/.ssh/id_ed25519
. We add it to the activated SSH agent using the ssh-add
command.
Note: You need to add a config file before using the command on MacOS.
Next, log in to GitHub and store the public the key under SSH (New) key text box. Use this path: Settings->SSH and GPG keys
Now that you have securely connected two remote machines, let’s invoke and solve the error fatal: could not read from remote repository.
ALSO READ: git tag usage explained for beginners [Easy Examples]
Source~1: Pushing to non-existing remote
Despite authenticating the local machine, Git and GitHub may fail to understand each other if you attempt to push to a remote repository that does not exist.
Let’s build a local repository and attempt to push the changes to a non-existing remote.
Steps
steve@thisHostname:~$ mkdir test_repo && cd test_repo steve@thisHostname:~/test_repo$ git init Initialized empty Git repository in /home/steve/test_repo/.git/ steve@thisHostname:~/test_repo$ cat >> example.py print('Hello world') steve@thisHostname:~/test_repo$ git status On branch main No commits yet Untracked files: (use "git add <file>..." to include in what will be committed) example.py nothing added to commit but untracked files present (use "git add" to track) steve@thisHostname:~/test_repo$ git add . steve@thisHostname:~/test_repo$ git commit -m "Testing 1, 2, 3" [main (root-commit) aae3b47] Testing 1, 2, 3 1 file changed, 1 insertion(+) create mode 100644 example.py steve@thisHostname:~/test_repo$ git log commit aae3b47090a9fc9cc561fee37fd3077864fe573b (HEAD -> main) Author: Stevealila <stevealila25@gmail.com> Date: Tue Feb 7 10:43:37 2023 +0300 Testing 1, 2, 3
We create test_repo
directory and convert it to a Git repository using the git init
command. We then create example.py
file in the working directory before staging and committing the changes.
Problem
Two errors pop up on attempting to push changes to an unknown remote. One of the errors is fatal: Could not read from remote repository.
steve@thisHostname:~/test_repo$ git push origin main fatal: 'origin' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.
Solved
The solution is to create the repo
and set its URL as the local repository’s remote URL.
steve@thisHostname:~/test_repo$ git remote add origin https://github.com/Stevealila/test_repo.git steve@thisHostname:~/test_repo$ git remote set-url origin git@github.com:Stevealila/test_repo.git steve@thisHostname:~/test_repo$ git push origin main Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Writing objects: 100% (3/3), 237 bytes | 237.00 KiB/s, done. Total 3 (delta 0), reused 0 (delta 0), pack-reused 0 To github.com:Stevealila/test_repo.git * [new branch] main -> main
Now the connection goes through after adding or setting the remote connection.
ALSO READ: Git rename branch — local and remote (PROPERLY)
Source~2: Incorrectly linking through SSH keys
You may also get the error when you fail to connect the machines with the SSH keys correctly.
For example, you could be pushing to or cloning from the remote after connecting the machines with SSH for the first time.
The (local) machine asks, «Are you sure you want to continue connecting (yes/no/[fingerprint])?» You should input ‘yes’ followed by clicking the enter key. If you input ‘no’ or leave it blank, the connection fails and throws the error fatal: could not read from remote repository.
Problem
steve@thisHostname:~$ git clone git@github.com:Stevealila/Python.git pyFiles
Cloning into 'pyFiles'...
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Host key verification failed.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
solved
steve@thisHostname:~$ git clone git@github.com:Stevealila/Python.git pyFiles
Cloning into 'pyFiles'...
The authenticity of host 'github.com (140.82.121.4)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
remote: Enumerating objects: 10, done.
remote: Counting objects: 100% (10/10), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 10 (delta 0), reused 4 (delta 0), pack-reused 0
Receiving objects: 100% (10/10), done.
The pull process goes through after we type ‘yes’.
Conclusion
You just learned the main causes of the error fatal: could not read from remote repository and how to solve them. Now it is your turn to apply the knowledge.
Ad
At Career Karma, our mission is to empower users to make confident decisions by providing a trustworthy and free directory of bootcamps and career resources. We believe in transparency and want to ensure that our users are aware of how we generate revenue to support our platform.
Career Karma recieves compensation from our bootcamp partners who are thoroughly vetted before being featured on our website. This commission is reinvested into growing the community to provide coaching at zero cost to their members.
It is important to note that our partnership agreements have no influence on our reviews, recommendations, or the rankings of the programs and services we feature. We remain committed to delivering objective and unbiased information to our users.
In our bootcamp directory, reviews are purely user-generated, based on the experiences and feedback shared by individuals who have attended the bootcamps. We believe that user-generated reviews offer valuable insights and diverse perspectives, helping our users make informed decisions about their educational and career journeys.
Find the right bootcamp for you
X
By continuing you agree to our
Terms of Service and Privacy Policy, and you consent to
receive offers and opportunities from Career Karma by telephone, text message, and email.
Fatal: could not read from remote repository. is a Git error message when it fails to connect to your “remote repository” due to a configuration error on your local machine. This article will explain what’s wrong with your compiler and how you can connect to your remote repository.
While you go through this article, you’ll learn more about Git and how it works behind the scenes. Now, you’ll need your terminal or command prompt to follow along, so launch either and let’s restore your connection.
Contents
- Why Git Cannot Read From Your Remote Repository?
- – Your SSH Key Was Removed From the SSH Agent
- – Your Remote URL Is SSH in the Configuration File
- – Another Program Is Using the git_SSH Environment Variable
- – Your SSH Agent Is Not Running
- – Network Access Problems on Your Computer
- – Mismatch of the Local and Remote SSH Key
- – You Did Not Specify the Remote URL Location
- How Git Can Read From Your Remote Repository
- – Add Your SSH Key to Your SSH Agent
- – Update the Remote URL in the Configuration File
- – Remove git_SSH Environment Variable
- – Start Your SSH Agent
- – Access the Remote Repository Using a Vpn
- – Update the Remote SSH Key
- – Set a Remote URL for Git Push Operations
- Conclusion
Why Git Cannot Read From Your Remote Repository?
Git cannot read from your remote repository because your SSH key was removed from the SSH agent, or the remote URL is SSH in the Git configuration file. Other causes include a mismatch of your local and remote SSH keys, network access problems, or your SSH agent is not running.
The following can also prevent Git from reading from your remote repository:
- Mismatch of the local and remote SSH key
- You did not specify the remote URL location
– Your SSH Key Was Removed From the SSH Agent
If you’re connecting to your “Git repository” and your “SSH key” was removed from the SSH agent, Git cannot read from your remote repository. As a result, you’ll get an error because this key allows you to authenticate to the repository without typing your password every time.
So without it, the server hosting the remote repository cannot verify your identity during the connection, and like every system, it will stop you. Factors that can remove your SSH key from the agent include the following:
- Explicit removal using the “ssh-add -D” command.
- Manual deletion of the key file.
- Another program deleted the key without your knowledge.
– Your Remote URL Is SSH in the Configuration File
When the remote URL is SSH in the configuration file (“.git/config”), Git cannot connect to your remote repository if the repository owner did not configure SSH access. So, when you try any “git” operations like “git push”, the communication with the remote repository will break down because there is no medium to continue.
For example, the value of the “url” in the following indicates that you’ll like to connect to a GitHub repository using SSH. But you’ll get an error message that includes “access rights”, “correct access” if you did not configure SSH on your repository:
url = git@github.com:your_github_username/your_github_repository.git
– Another Program Is Using the git_SSH Environment Variable
When another computer program on your computer is using the GIT_SSH environment variable, Git will show you an error if you want to read from a remote repository. This type of situation occurs when Cygwin is your preferred terminal environment, and it works fine with SSH.
However, you installed Git on your Windows computer, and this Git installer changed the GIT_SSH variable to “Plink.exe”. The latter is the “PuTTY link” command line tool that will not work with SSH unless you configure it for SSH.
Now, this leads to a conflict on your computer because “Plink.exe” is now using the GIT_SSH variable that’s meant for your configured SSH client in Cygwin. As a result, your SSH client can’t use this environment variable for SSH connections, and you’ll get an error if you initiate an operation that will use SSH.
– Your SSH Agent Is Not Running
The SSH agent is “ssh-agent,” and if it’s not running, you cannot initiate any SSH connection to your remote repository. Here is why: this agent will store your SSH private key that’ll allow you to connect to your remote repository that’s configured for SSH connections. Now, if the agent is not running, you’ve lost the authentication link between your computer and the remote repository. So, when you try a “git push” or “git pull” operation, Git will show an error that it can’t read from your remote repository.
– Network Access Problems on Your Computer
Network access problems on your computer can cause a breakdown of communications between your computer and your remote repository. Your work environment can have network policies in place that can disrupt your Git operations in the name of security.
This can include the use of proxy servers that can decrypt your web traffic while it flows from your computer to the remote repository. The time frame for this operation by the proxy server can prevent Git from reading from your remote repository.
– Mismatch of the Local and Remote SSH Key
The SSH keys on your local machine and your remote repository should be the same for any successful SSH connection. If there is a mismatch (or the key does not exist at all), your Git client will not connect if you’ve configured it for SSH connections.
That’s because the standard way to connect via SSH is to create the key on your computer and upload the same key to your remote repository. Now, if the keys are different, the server that’s hosting your remote Git repository will show a “fatal cannot read error” for your incoming Git operations.
– You Did Not Specify the Remote URL Location
A remote URL location is where you’ll push and pull code from and if you don’t set it, the Git client will have no idea where you want to send your code. As a result, if you try to push your code from your local machine, you’ll get the “fatal read” error. For GitHub, it supports SSH URL and HTTPS URL for remote URL locations, but you’ll get an “correct access rights” error if you don’t set either on your local machine.
How Git Can Read From Your Remote Repository
Git can read from your remote repository if you add your SSH key to your SSH agent, update the remote URL in the configuration file, or remove the GIT_SSH environment variable. Starting your SSH agent or accessing the remote repository using a VPN also works.
Finally, you can update the remote SSH keys or set a remote URL for “git push” operations.
– Add Your SSH Key to Your SSH Agent
The addition of your SSH key to your SSH agent will allow your Git client to connect to your remote repository, and it also prevents the “fatal read error” when you do a “git push”. To add your SSH key to the SSH agent, do the following:
- Open your terminal on Linux
- Start the SSH agent using the following command: eval ssh-agent -s
- Use “exec ssh-agent XXXX” on CentOS where XXXX is the name of your shell environment. For example: “exec ssh-agent fish”
- Hit enter on your keyboard.
- Type the following to add your SSH key: ssh-add ~/.ssh/id_rsa
- Press enter on your keyboard to add the key.
- Try your Git operations, and it should work.
If you’re on a Windows computer, do the following instead:
- Download Git Bash from their official website.
- Type and run the following: eval $(ssh-agent)
- Use the following if the previous command does not work: eval “$(ssh-agent -s)”
– Update the Remote URL in the Configuration File
If you don’t have SSH configured on the remote repository, you should update the URL in the configuration file to HTTPS. You can change your remote URL to HTTPS using the following steps:
- Open your terminal.
- Navigate to your project folder
- List the remote URLs using the following: git remote -v
- Note the name of the remote URLs from the previous command.
- Change the remote URL from Secure Socket Shell (SSH) to HTTPS using the following: git remote set-url origin https://github.com/your_GitHub_username/the_name_of_the_Git_repository.git
- Confirm the changes using the following: git remote -v
- Try your Git operations, and it should work.
Meanwhile, if you don’t want to use the command line, you can do the following to get the same results:
- Open the Git configuration file (“.git/config”). On Windows, it’s a hidden file, and you’ll have to show hidden files via the control panel.
- Change the value of the “url” from something like “git@github.com:your_GitHub_username/the_name_of_the_Git_repository.git” to “https://github.com/your_GitHub_username/the_name_of_the_Git_repository.git”
– Remove git_SSH Environment Variable
The removal of the GIT_SSH environment variable will prevent the “fatal” read error if your environment is Cygwin and another program is interfering. To remove the GIT_SSH environment variable, do the following:
- Open your terminal or command prompt.
- Type and run the following command: unset GIT_SSH
- Restart your Git client and restart your computer.
- Try a Git operation like “git push” in Cygwin, and it should work.
– Start Your SSH Agent
Your SSH agent is the most important thing when working with the remote repository that’s configured for SSH access. To start your SSH agent, do the following:
- Open your terminal.
- Type and run the following: eval ssh-agent -s
- Try your Git operations and if you get an error, add your SSH key using the “ssh-add” program.
Please note, start the agent using the “eval” as we did above. If you don’t, Git will complain that it cannot connect to your authentication agent. That’s because using “eval” to start the agent will create an environment variable that allows SSH to find the SSH agent. However, if you start the agent as “ssh-agent”, it will start, but SSH will not find it.
– Access the Remote Repository Using a Vpn
If you’re in a corporate environment and you’re getting the “fatal cannot read from remote repository” error, setup a Virtual Private Network (VPN). With a VPN running on your computer, your computer traffic will go through it and connect to your GitHub repository.
– Update the Remote SSH Key
When you update the remote SSH key to match that on your local machine, Git will connect via SSH without an error. To do this update, do the following:
- Open your terminal.
- Type the following and replace “your_email_id@host.com” with your real email address: ssh-keygen -t rsa -C “your_email_id@host.com”.
- Copy the generated RSA “public key” using the following command: cat ~/.ssh/id_rsa.pub
- Go to your remote Git repository and paste the key. For GitHub, continue with the next steps.
- Log in to your GitHub account.
- Click your profile picture in the top-right corner and click on “Settings”.
- Click on SSH and GPG keys in the “Access” section.
- Click on “Add SSH key” and add a descriptive label for the new key.
- Select the purpose of the key.
- Paste the key that you copied from your computer and click on “Add SSH key”.
– Set a Remote URL for Git Push Operations
Before you can push to your remote repository, you need to set up a remote URL for the operation. There are methods that you can use, and the following steps detail the first method:
- Open your terminal. On Windows, install GitBash.
- Switch to your project directory using the terminal.
- Type and run the following command: git remote set-url origin https://github.com/your_GitHub_username/your_GitHub_repository.git
The following steps detail the second method, and it’s a modification of the Git’s configuration file:
- Open your terminal. On Windows, install GitBash.
- Switch to your project directory using the terminal.
- Move to the “.git” subdirectory.
- Open the “config” file in your code editor.
Paste the following in the “config” file: [remote “origin”]
url = https://github.com/your_GitHub_username/your_GitHub_repository.git
- fetch = +refs/heads/:refs/remotes/origin/
Conclusion
This article explained why Git could not read from your remote repository and what you can do to fix it. From our entire discussion, remember the following:
- If your SSH key is missing from the SSH agent, Git cannot read from your remote repository.
- When the SSH agent is not running, an attempt to connect to your remote Git repository using SSH will result in the “fatal read” error.
- You can fix the “fatal could not read from remote repository” error if you add your SSH key to your SSH agent or you switch to HTTPS in the Git configuration file.
Now, you know what it takes to connect to Git without a “fatal” or “permission denied” error. Share our article with your fellow developers and tell them about our site.
- Author
- Recent Posts
Your Go-To Resource for Learn & Build: CSS,JavaScript,HTML,PHP,C++ and MYSQL. Meet The Team
Before pushing content to the GitHub repository or pulling remote content to the local directory, it is required to connect the local machine with the remote server. If the repositories are not connected or provide a wrong URL, developers often encounter a “fatal: Could not read from remote repository” error.
This study will provide the solution of fixing the “git fatal” error.
To fix the above-stated error, first, navigate to the local repository and check the remote URL list. If the remote is not added, then open GitHub, move to the required repository, and copy its “HTTP” URL. Finally, add the copied URL to the list and connect the remote repository with the local repository using the “git remote add <remote> <URL>” command.
Step 1: Switch to Required Directory
First, type out the below-provided command and redirect to the local repository:
Step 2: Create File
Then, utilize the “touch” command to generate an empty file:
Step 3: Stage Changes
Track newly added changes to the staging index with the help of the “git add” command:
Step 4: Commit Changes
Next, run the following command to save the staging index changes:
$ git commit -m «New file added»
Step 5: Fetch Remote Origin
Then, download the content of the GitHub repository in the local repository using the below-stated command:
Note: It can be seen that there is an error, and the “origin” could not get fetched. So, to resolve this issue, follow the next steps.
Step 6: List Remote URL
Verify whether the local repository is connected to the remote server or not:
The below output indicates that the remote repository has not been connected to the local repository:
Step 7: Copy Remote URL
Open GitHub, choose a particular remote repository, and copy its “HTTPS” URL:
Step 8: Add Remote URL
Now, run the following command to link both repositories, such as remote and local:
$ git remote add origin https://github.com/laibayounas/newRepo.git
Step 9: Verify Added Remote URL
To ensure whether the remote URL has been added or not, use the following command:
Step 10: Fetch Remote Origin
Lastly, fetch the remote server content again to the Git local repository:
In the screenshot below, it can be observed that the remote content has been successfully downloaded to the local repository:
That’s all! We have provided the easiest solution for fixing the above-stated error.
Conclusion
In order to fix the “git: fatal: Could not read from remote repository” error, first, redirect to the local repository and check whether it is connected to the remote repository. If the remote URL is not added, then open GitHub, move to the desired remote repository, and copy its HTTP URL. Lastly, run the “git remote add <remote> <URL>” command to set the remote URL. This study explained the solution for the “git fatal” error.
About the author
I have done bachelors in Computer Science. Being passionate about learning new technologies, I am interested in exploring different programming languages and sharing my experience with the world.