常见的git命令和git->github错误

132 阅读1分钟

相关命令

  1. git remote

     git remote add origin xxx (xxx为仓库链接)
    

    给这个链接取一个名字,为origin

  2. git pull

    git pull <远程主机名>  <远程分支名>:<本地分知名>
    
  3. git push

    git push origin main
    
  4. 删除一个远程仓库

    git remote rm xxx(仓库名)
    
  5. 修改一个远程仓库链接

    git remote set-url origin <remote-url>
    
  6. 查询仓库

    git remote -v
    

常见错误

  1. 把本地的master分支重命名为main

    git branch -m master main
    
  2. 当Failed to connect to 127.0.0.1 port 1080

    // 首先,查一下当前全局的 http 代理:
    git config --global http.proxy
    // 如果有代理,就取消
    git config --global --unset http.proxy
    ​
    ​
    // 再查 https 的代理:
    git config --global https.proxy
    // 同样的,有就取消
    git config --global --unset https.proxy
    ​
    
  3. 当'credential-manager' is not a git command

    git config --global credential.helper wincred
    
  4. 当OpenSSL SSL_read: Connection was reset

    git config --global http.sslVerify "false"
    
  5. 当fatal: refusing to merge unrelated histories

    问题分析:出现这个问题的最主要原因还是在于本地仓库和远程仓库实际上是独立的两个仓库。假如我之前是直接clone的方式在本地建立起远程github仓库的克隆本地仓库就不会有这问题了。

     git pull origin main --allow-unrelated-histories
    
  6. 当Everything up-to-date,但实际上你已经添加了文件,但没有上传成功,所以此时重新add,commit

    git add .
    git commit -m "hellloworld"
    git push origin main
    
  7. 当github出现一个→的白色箭头,这是因为上传的目录有.git文件,github当作子模块了。

    删除子文件夹里面的.git文件
    git rm --cached [文件夹名]
    git add .
    git commit -m "helloworld"
    git push origin main
    ​
    

\