手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

使用Git连接本地和远程GitHub

[日期:2019-07-28] 来源:Linux社区  作者:chencarl [字体: ]

网上很多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

Linux公社的RSS地址https://www.linuxidc.com/rssFeed.aspx

本文永久更新链接地址https://www.linuxidc.com/Linux/2019-07/159631.htm

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款