git推送到远程存储库“无法从远程存储库读取” [英] git push to remote repository "Could not read from remote repository"

查看:347
本文介绍了git推送到远程存储库“无法从远程存储库读取”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了一段时间,但找不到解决问题的办法。



我有一台服务器,可以通过ssh使用用户名 git 和一个本地git仓库。

现在我想将我的本地仓库推到服务器上新创建的仓库。



这是我做的:


  • / home / git中创建了一个git仓库/test.git

  • 将存储库初始化为空

  • 在本地计算机上添加了远程存储库

    git remote add test ssh:// git @ serverIp:/home/git/test.git
  • 现在我执行了
  • push命令:

    git push test master




我总是得到




 致命:无法读取远程存储库

请确保您拥有正确的访问权限
并存在存储库。

我正在使用本地Windows 7计算机,并希望上传到Linux服务器。

我可以通过ssh使用 git 用户登录。
我也尝试将它作为 root 用户(让事情工作一次)得到相同的结果。

我从来没有得到过要求为ssh 密码



我真的不知道我在做什么错误。

在你称之为重复之前,我对这个问题进行了很多搜索,而且似乎没有人谈论过同样的问题。



更新:




  • 哪个git返回/ usr / bin / git

  • PATH echo包含/ usr / li>
  • id_rsa和id_rsa.pub文件全部设置并且输入密码

  • ssh git @ serverIp哪个git-receive-pack可以工作并返回/ usr / bin / git-receive-pack

  • ssh git @ serverIp ls /home/git/test.git works

  • 所有相关的目录都是chmod 755

  • git是存储库的所有者

  • auth.log文件在尝试的推送命令中没有新条目

  • GIT_TRACE = 2 git push test主返回:


    'C :\ Program Files(x86)\PTTTY\plink.exe''-batch''git @ serverIp''git-receive-pack'\''/ home / git / test.git'\'' '致命的:无法从远程存储库读取。请确保您拥有正确的访问权限并存在存储库。




解决方案

在这种情况下,使用openssh over putty是关键。






原始答案用于调试)


我可以通过ssh使用 git 用户登录。 / p>

这意味着这可以工作:

  ssh git @ serverIp 

您有一个 HOME 变量定义,以及 id_rsa / id_rsa.pub ) >%HOME%/。SSH / 。



这个问题建议使用不同的网址:

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

请确保您创建了git repo作为git(而不是root用户,当您创建git帐户时,如此问题)。

ssh git @ serverIp其中git应该返回git可执行文件的路径。



检查所有父目录是否设置了相关的 x (执行)位对于用户 git 或组 gitgroup ,运行 ls -ld / home / home / git /home/git/test.git

另外,获取更多git命令的信息可以使用:


  • git push --verbose


    或:

  • GIT_TRACE = 2 git push test master



如果你有一个私有ss h键输入密码,最好先用私钥ssh命令测试这些ssh命令而不是密码保护,以查看问题是否仍然存在。

或者,您可以保留该密码保护的ssh密钥,但仔细检查您的 .bashrc 为在这个答案






对于任何ssh连接问题(需要git的密码),检查: / p>


  • /var/log/auth.log

  • sshd调试会话

  • ul>




    在你的情况中,因为它适用于 ssh git @ serverIp 交互式安全shell),而不是使用git(它打开一个非交互式安全shell),请查看此线程,其中引用


    使用命令行启动ssh时,将启动非交互式非登录shell。

    但是... bash 在这种情况下不使用 $ BASH_ENV ,因此将其设置为〜/ .ssh / environment (例如到 / etc / profile )没有帮助。

    bash的作用是源 / etc / bashrc 〜/ .bashrc

    确保 / etc / profile 确实定义了路径为 git ,因为非登录帐户可以在这里使用(这似乎是这种情况,因为 ssh git @ serverIpgit工作,并且 ssh git @ serverIpgit --version也应该)。

    正确的问题,然后在 / home / home / git 上测试 chmod 755 / code>和 /home/git/test.git


    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.

    解决方案

    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:


    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.

    这篇关于git推送到远程存储库“无法从远程存储库读取”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆