zoukankan      html  css  js  c++  java
  • 使用git连接本地和远程github

    使用git连接本地和远程github

    网上很多github的流程比较乱,自己尝试整理了一下,主要是步骤较为清晰,如果有不清楚的可详细进行搜索对比

    1. 申请和设置github

    https://github.com/
    该过程请自行参考

    2. 使用gitbash设置用户名和邮箱

    打开gitbash,输入命令设置用户名和邮箱

    $ git config --global user.name "your name"
    $ git config --global user.email "your email"
    

    3. 生成ssh配置

    通过邮箱名称生成ssh key,在输入第一行命令后火提示输入保存key的地址,根据自己的结构指定文件的地址,

    $ ssh-keygen -t rsa -C "xxx@gmail.com"
    Generating public/private rsa key pair.
    Enter file in which to save the key (/c/Users/kf/.ssh/id_rsa): D:/ssh/github
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in D:/ssh/github.
    Your public key has been saved in D:/ssh/github.pub.
    The key fingerprint is:
    SHA256:8J70WllHBwvnolh+LVG2pIOMKRkhzJibLjyoiZNBXvA 
    xxx@gmail.com
    The key's randomart image is:
    +---[RSA 2048]----+
    |   =. o.    . *  |
    | .o o. o + . O + |
    |  oo  + o + = = .|
    | .oE   + + . * . |
    |=..     S o + o  |
    |++.    o o + o   |
    |o=.     o +      |
    |*        o       |
    | .      .        |
    +----[SHA256]-----+
    

    4. 配置github ssh

    执行成功后,生成目录下会生成两个文件,一个是私钥一个是公钥,找到后缀是 .pub 的公钥文件,拷贝全部文件内容到github中,具体方法是在github页面中Settings > SSH and GPG keys > New SSH key 中设置,title内容随意设置。

    5. 配置本地ssh

    执行ssh-add -l 查看本地ssh配置情况

    $ ssh-add -l
    

    如果返回如下,则说明配置正确

    2048 SHA256:8J70WllHBwvnolh+LVG2pIOMKRkhzJibLjyoiZNBXvA /d/ssh/github (RSA)
    

    如果返回下面一句话,这说明没有起效

    Could not open a connection to your authentication agent.
    

    需要执行如下语句:

    $ ssh-agent bash
    $ ssh-add /d/ssh/github
    

    6. 验证连接

    ssh配置成功后验证是否能够正确连接github

    $ ssh -T git@github.com
    Hi xxx! You've successfully authenticated, but GitHub does not provide shell access.
    

    7. 与github同步

    将本地项目上传到github

    $ git remote add origin git@github.com:your_project.git  
    $ git push -u origin master 
    

    如果本地没有则先下载到本地再同步

    $ git clone your_project.git  
    $ git push -u origin master
  • 相关阅读:
    使用子查询可提升 COUNT DISTINCT 速度 50 倍
    页面装载js及性能分析方法
    用CSS创建打印页面
    每个Web开发者都应该知道的关于URL编码的知识
    C IO programming test code
    全球NTP服务器列表
    MySQL数据的查询注意
    Python使用pyMysql模块插入数据到mysql的乱码解决
    单元测试
    python threading.thread
  • 原文地址:https://www.cnblogs.com/chencarl/p/10336858.html
Copyright © 2011-2022 走看看