Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push to remote repository "Could not read from remote repository"

I searched for a while but I can't find a solution to my Problem.

I have a Server I can connect to via ssh with the username git and a local git repository.
Now I want to push my local repository to a newly created one on the Server.

Here is what I did:

  • created a git repository in /home/git/test.git
  • initialized the repository as bare
  • added the remote repository on the local machine
    git remote add test ssh://git@serverIp:/home/git/test.git
  • now I executed the push command:
    git push test master

I always get the

fatal: could not read from remote repository  Please make sure you have the correct access rights and the repository exists. 

I am working on a local windows 7 machine and want to upload to a linux server.
I can log in via ssh with the git user. I also tried to do this as the root user(to get things to work once) with the same result.
I never get asked for the ssh password.

I really don't know what I am doing wrong.
Before you call this a duplicate, I searched a lot for this problem and none seemed to talk about the same problem.

update:

  • "which git" returns /usr/bin/git
  • PATH echo includes /usr/bin
  • id_rsa and id_rsa.pub files are all set up and withput Passphrase
  • ssh git@serverIp which git-receive-pack works too and returns /usr/bin/git-receive-pack
  • ssh git@serverIp ls /home/git/test.git works
  • all relevant directories are chmod 755
  • git is owner of the repository
  • auth.log file gets no new entries on tried push command
  • GIT_TRACE=2 git push test master returns:

    'C:\Program Files (x86)\PuTTY\plink.exe' '-batch' 'git@serverIp' 'git-receive-pack '\''/home/git/test.git'\''' fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

like image 218
user1090755 Avatar asked Apr 20 '13 09:04

user1090755


People also ask

Does not appear to be a git repository could not read from remote repository?

Note: The “fatal: 'origin' does not appear to be a git repository” error occurs when you try to push code to a remote Git repository without telling Git the exact location of the remote repository. To solve this error, use the git remote add command to add a remote to your project.

How do I push to a remote git repository?

In order to push a Git branch to remote, you need to execute the “git push” command and specify the remote as well as the branch name to be pushed. If you are not already on the branch that you want to push, you can execute the “git checkout” command to switch to your branch.

How do I fix remote repository not found?

Fix 5 - Git - remote: Repository not found Just run the git remote update command which updates the local repo with the remote repo and its credentials. If this command is executed without any issues then your issue will be resolved.


2 Answers

In this case, using openssh over putty was key.


Original answer (tips for debugging)

I can log in via ssh with the git user.

That means this works:

ssh git@serverIp 

You do have a HOME variable defined, and ssh public/private keys (id_rsa / id_rsa.pub) in %HOME%/.ssh/.

This question suggests a different url:

git remote set-url test git@serverIp:/home/git/test.git 

Make sure you did create your git repo as git (and not as root, when you created the git account, as in this question).
ssh git@serverIp "which git" should return the path of the git executable.

Check also that all parent directories have the relevant x (execute) bit set for the user git or the group gitgroup, running ls -ld /home /home/git /home/git/test.git.
Also, getting more info for a git command can be done with:

  • git push --verbose
    or:
  • GIT_TRACE=2 git push test master

If you have a private ssh key with a password, it would be best to first test those ssh commands with a private ssh key not password-protected, to see if the issue persists.
Or, you can keep that password-protected ssh key, but double-check your .bashrc as in this answer.


For any ssh connection issue (where git's password is needed), check:

  • /var/log/auth.log,
  • an sshd debug session

In your case, since it works with ssh git@serverIp (interactive secure shell), but not with git (which opens a non-interactive secure shell), have a look at this thread, which references this one:

When ssh is started with a commandline, a non-interactive non-login shell is started.
However...bash does not use $BASH_ENV in this case, so setting it in ~/.ssh/environment (e.g. to /etc/profile) doesn't help.
What bash does is source /etc/bashrc and ~/.bashrc.

Make sure that /etc/profile does define the path for git, since a non-login account could be used here (that seems to be the case here, since ssh git@serverIp "which git" worked, and ssh git@serverIp "git --version" should too).

But check also the right issue, and test a chmod 755 on /home, /home/git and /home/git/test.git.

like image 110
VonC Avatar answered Oct 03 '22 03:10

VonC


You can also check your SSH identities by doing:

$ ssh-add -L 

I had a similar problem. There was a wrong key in my identities, don't remember why. I just delete all my identities (maybe you will need to add keys again):

$ ssh-add -D   

Then I did push/pull without problems.

like image 40
Matias Avatar answered Oct 03 '22 02:10

Matias