Post

Git常见问题解决方法

Git常见问题解决方法

1. git clone失败

1.1 问题描述

使用git clone时出现下面的报错:

1
2
3
4
5
6
7
8
9
xiaowu@DESKTOP-FE78O6H MINGW64 /e/blog (master)
$ git clone git@github.com:xxiaowuer/xxiaowuer.github.io.git
Cloning into 'xxiaowuer.github.io'...
kex_exchange_identification: Connection closed by remote host
Connection closed by 198.18.0.143 port 22
fatal: Could not read from remote repository.

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

原因分析

通过查阅相关解决方法,发现可能是我开了代理的原因

解决方法

  1. 关闭代理

  2. 改用HTTPS协议,走443端口

    ~/.ssh/config 文件中添加下面的配置即可,之后就可以正常使用 git pull 等操作了

    1
    2
    3
    4
    
    Host github.com
        Hostname ssh.github.com
        Port 443
        User git
    

参考教程

  1. Github官方教程
  2. 大佬博客

2. git push失败

2.1 问题描述

1
2
ERROR: Permission to xxiaowuer/xxiaowuer.github.io.git denied to xiaowu003.
fatal: Could not read from remote repository.

原因分析

git的本地邮箱没有被添加到该仓库的协作者中,所以push操作被拒绝

解决方法

  1. 申请成为协作者

  2. 如果是自己的仓库,那么将git本地的邮箱改为仓库的github账号的邮箱

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    
    xiaowu@xx MINGW64 /e
    $ git config --global --list
    core.editor="D:\VsCode\Microsoft VS Code\bin\code" --wait
    user.name=<name>
    user.email=xxx@163.com
    http.sslverify=false
    http.proxy=http://127.0.0.1:7897
    https.proxy=http://127.0.0.1:7897
       
    xiaowu@xx MINGW64 /e
    $ git config --global user.email "<github-email>"
       
    xiaowu@xx MINGW64 /e
    $ git config --global --list
    core.editor="D:\VsCode\Microsoft VS Code\bin\code" --wait
    user.name=<name>
    user.email=<github-email>
    http.sslverify=false
    http.proxy=http://127.0.0.1:7897
    https.proxy=http://127.0.0.1:7897
    
This post is licensed under CC BY 4.0 by the author.