解决Git报错[cloned an empty repository,,,][have the correct access rights,,,]

在仓库中,git pull报错,

kex_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

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

Git新建仓库,git clone告警,

warning: You appear to have cloned an empty repository.

解决以上问题,在git地址正确的前提下,需要注意两个问题:

(1)权限问题
(2)确保当前pull的不是空仓库。

下文分别记录处理过程

权限

搭建git服务器,参考CentOS7搭建Git服务器简易笔记

服务器端,repo文件夹需要git用户有权限访问

[root@yix]# mkdir yix_project.git
[root@yix repo]# chown yix_git:yix_git yix_project.git
[root@yix repo]# cd yix_project.git/
[root@yix repo]# git init --bare yix_project.git
Initialized empty Git repository in /data/repo/yix_project.git/
[root@yix repo]# chown -R yix_git:yix_git * -R

空仓库

在客户端(以下是小编Windows平台使用 Git Bash的操作日志),

创建文件 readme.md 内容任意,如:I have a dream.

$ touch readme.md
$ vim readme.md

git add 当前文件夹内容,并且查看git状态

$ git add *
$ git status

终端回显

On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)
        new file:   readme.md

输入命令,提交(git commit)

$ git commit -m "init"

终端回显

[master (root-commit) 8178856] init
 1 file changed, 1 insertion(+)
 create mode 100644 readme.md

[master (root-commit) 8178856] init
 1 file changed, 1 insertion(+)
 create mode 100644 readme.md

输入命令,push

$ git push

回显内容

yix_git@yix's password:
Enumerating objects: 3, done.
Counting objects: 100% (3/3), done.
Writing objects: 100% (3/3), 206 bytes | 29.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To yix:/repo/yix_project.git

 * [new branch]      master -> master

在拉一下看看 (git pull)

$ git pull

正常成功回显内容

yix_git@yix's password:
Already up to date.

yix_git@www.yixzm.cn's password:
Already up to date.
版权声明

弈心博客


本文首发site_name,转载请附上博文链接!