美文网首页
githup使用记录

githup使用记录

作者: James999 | 来源:发表于2020-07-10 11:11 被阅读0次

    ================================windows10 使用记录===============================

    初始化与设置

    git init // 把这个目录变成Git可以管理的仓库
    git add README.md // 文件添加到仓库
    git add . // 不但可以跟单一文件,还可以跟通配符,更可以跟目录。一个点就把当前目录下所有未追踪的文件全部add了 
    git commit -m "first commit" // 把文件提交到仓库
    git remote add origin git@github.com:wangjiax9/practice.git // 关联远程仓库
    git push -u origin master // 把本地库的所有内容推送到远程库上
    

    error log

    Warning: Permanently added 'github.com,*******' (RSA) to the list of known hosts.
    git@github.com: Permission denied (publickey).
    fatal: 无法读取远程仓库。
    

    原因可能是没有与githup上的账号成功建立密钥对,所以需要配对密钥.

    解决方法:

    1. ssh-keygen -t rsa -C "youremail@example.com"  
    // 注意是:youremail@example.com 是你githup上验证的账户
    2. ssh -v git@github.com
    3. ssh-agent  -s
    4. ssh-add ~/.ssh/id_rsa   // 这步骤可能会报错
    errorlog : Could not open a connection to your authentication agent,
    则先执行如下命令即可:
    ssh-agent bash
    成功后继续执行 4. 
    success log: Identity added:Identity added: /home/may/.ssh/id_rsa (****@163.com)
    5. 则存储在</c/Users/may/.ssh/id_rsa>,之后步骤中执行的命令应该相应改为
    ssh-add /c/Users/may/.ssh/id_rsa
    6.  cat  ~/.ssh/id_rsa.pub
    

    命令6.执行后id_rsa.pub文件内容将输出到终端,复制里面的密钥(内容一般是以ssh-rsa 开头,以gitee账号的注册邮箱结尾的,全部复制下来)

    然后进入你的https://github.com/settings/keys
    添加SSH Key

    7. 接着在执行 ssh -T git@github.com
    

    最后 又再次执行 git push -u origin master
    error log:
    To github.com:*******/*****.git
    ! [rejected] master -> master (fetch first)
    error: 推送一些引用到 'git@github.com:*****/*****.git' 失败
    提示:更新被拒绝,因为远程仓库包含您本地尚不存在的提交。这通常是因为另外
    提示:一个仓库已向该引用进行了推送。再次推送前,您可能需要先整合远程变更
    提示:(如 'git pull ...')。
    提示:详见 'git push --help' 中的 'Note about fast-forwards' 小节。

    Root cause
    原因可能是之前上传时创建的.git文件被删除或更改,或者其他人在github上提交过代码.

    8. a.强行上传   git push -u origin +master
        b. 尽量先同步github上的代码到本地,在上面更改之后再上传
    

    REF:

    GitHub 新手使用手册
    https://blog.csdn.net/wyp_comeon/article/details/91388107
    https://blog.csdn.net/qq_44919293/article/details/89451128
    https://www.jianshu.com/p/dd7f18ed0bb1
    https://www.jianshu.com/p/d97c6121952a

    ==================================================================

    Ubuntu20 使用记录
    sudo apt-get install git
    https://docs.github.com/cn/github/authenticating-to-github/connecting-to-github-with-ssh

    Ref:
    https://blog.csdn.net/qq_30243515/article/details/82080949

    相关文章

      网友评论

          本文标题:githup使用记录

          本文链接:https://www.haomeiwen.com/subject/frvpcktx.html