使用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

2019年GitHub上最受欢迎的7种编程语言 https://www.linuxidc.com/Linux/2019-05/158512.htm

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

栗子博客 软件 使用Git连接本地和远程GitHub https://www.lizi.tw/soft/15175.html

常见问题
  • 1、杰齐1.7仅适用于PHP5.2 2、需Zend支持 3、尽量使用宝塔面板 4、尽量使用Windows 系统,关关对Linux支持不太友好。
查看详情

相关文章

评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

使用Git连接本地和远程GitHub-海报

分享本文封面