配置github的SSH key及GitHub项目上传方式一——使用终端命令行
GitHub是一个开源的大仓库,我们经常从github上下载项目进行学习和研究,下面是一个完整的步骤——往GitHub上传一个新项目。
一、注册GitHub账号
1、注册GitHub账号,地址:https://github.com


2、登录:

3、登录之后的页面,是我们star其他人的一些信息,类似于QQ空间的好友状态

二、配置GitHub的SSH key
1、查看系统中是否配置过SSH keys,并处理
1.1 终端里输入显示隐藏文件:
defaults write com.apple.finder AppleShowAllFiles -bool true
输入命令完成之后需要重启Finder 桌面顶部苹果logo->强制退出->
就可显示隐藏文件。
还有一种方法,使用命令:cd ~/.ssh 检查是否已经存在ssh
1.2 然后前往个人文件查看有没有 .ssh 文件夹,有的话个人建议删除掉,从新配置

2、在本地配置SSH key
创建一个 .ssh 文件夹 命令:mkdir .ssh
gonganxinxideiMac-2:.ssh gonganxinxi$ mkdir .ssh
进入刚创建的 .ssh文件夹目录里 命令:cd .ssh
gonganxinxideiMac-2:.ssh gonganxinxi$ cd .ssh
命令:ssh-Keygen -t rsa -C “youEmail”,输入完成之后一直按回车键 中间会提示你要输入文件、密码,不用管一直按回车直到出现下面这样。
gonganxinxideiMac-2:.ssh gonganxinxi$ ssh-Keygen -t rsa -C “385584895@qq.com”
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/gonganxinxi/.ssh/id_rsa):
Created directory '/Users/gonganxinxi/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /Users/gonganxinxi/.ssh/id_rsa.
Your public key has been saved in /Users/gonganxinxi/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:2UDch+eu01e0XGA89tE89Kpnmdk+SlTLtxijRHaIX9w “385584895@qq.com”
The key's randomart image is:
+---[RSA 2048]----+
| ... . ..o.|
| .. + = Bo+|
| .. B * E+|
| ++ + o.=|
| S .+ +o++|
| . +.+B+|
| +.o*o.|
| o oo.o |
| . o. o|
+----[SHA256]-----+
指令:ls -la 查看 如果输出类似这样的信息,就说明配置成功
gonganxinxideiMac-2:.ssh gonganxinxi$ ls -la
total 0
drwxr-xr-x 2 gonganxinxi staff 68 9 1 16:50 .
drwx------ 6 gonganxinxi staff 204 9 1 16:50 ..
到目前这步应该不会有什么问题,我们继续。
拷贝SSH key,会在github上进行配置的时候使用
gonganxinxideiMac-2:.ssh gonganxinxi$ pbcopy < ~/.ssh/id_rsa.pub
3、在github配置SSH key
3.1 找到SSH key配置位置

3.2 填写SSH key配置信息

此处将在终端上使用命令pbcopy < ~/.ssh/id_rsa.pub拷贝的信息粘贴到4
位置,然后Add SSH key就添加完成了。
如图

4、回到终端,进行SSH确认连接
输入命令:ssh -T Git@github.com
执行完这条指令之后会输出 Are you sure you want to continue connecting (yes/no)? 输入 yes 回车
回到github,刷新网页就可以看到钥匙旁的灰色小圆点变绿,就表明已经添加成功了。此时github上面的SSH key 456会变成和123一样的绿色。(如果 网速慢,可能要稍等一会)
当然也有可能出现这样的问题:
gonganxinxideiMac-2:.ssh gonganxinxi$ ssh -T Git@github.com
The authenticity of host 'github.com (192.30.253.112)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
此时即使输入yes
Warning: Permanently added 'github.com,192.30.253.112' (RSA) to the list of known hosts.
Permission denied (publicly).
这个问题查了许久,发现是因为有时候防火墙会拒绝 SSH连接(Sometimes, firewalls refuse to allow SSH connections entirely. )在github的帮助中可以看到该问题。他们也给出了解决方案https://help.github.com/articles/using-ssh-over-the-https-port/
通过命令:ssh -T -p 443 git@ssh.github.com使用克隆过的SSH连接HTTPS端口。
gonganxinxideiMac-2:.ssh gonganxinxi$ ssh -T -p 443 git@ssh.github.com
The authenticity of host '[ssh.github.com]:443 ([192.30.253.123]:443)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[ssh.github.com]:443,[192.30.253.123]:443' (RSA) to the list of known hosts.
Hi zhangyanxiao! You've successfully authenticated, but GitHub does not provide shell access.
看见You’ve successfully authenticated, but GitHub does not provide shell access 。这就表示已成功连上github。
成功啦,棒棒哒!!!
下面可以在github创建仓库,上传项目了
三、创建项目仓库
1、创建github远程仓库

仓库创建完成后如图

2、创建git本地仓库
我们需要设置username和email,因为github每次commit都会记录他们。
git config --global user.name "github的用户名"
git config --global user.email"注册邮箱名"

cd到你的本地项目、根目录下,再执行git命令
gonganxinxideiMac-2:.ssh gonganxinxi$ cd /Users/gonganxinxi/Desktop/HexTurnRGB——Demo
git本地仓库初始化,这个时候可以在我们的项目文件中看到.git文件夹了
gonganxinxideiMac-2:HexTurnRGB——Demo gonganxinxi$ git init
Initialized empty Git repository in /Users/gonganxinxi/Desktop/HexTurnRGB——Demo/.git/
将本地项目的所有文件添加到暂存区中
gonganxinxideiMac-2:HexTurnRGB——Demo gonganxinxi$ git add .
将暂存区的文件提交到git本地仓库
命令:git commit -m "第一次提交" 双引号里面写注释语句
会出现很多如图,下面还有,没截进去。。。。

3、将git本地仓库和Github远程仓库关联
在github中打开要上传项目的远程仓库,得到网址
https://github.com/zhangyanxiao/HexTurnRGB

将本地仓库关联到Github上,后面的URL地址就是刚刚复制的github上仓库的https地址
gonganxinxideiMac-2:HexTurnRGB——Demo gonganxinxi$ git remote add origin https://github.com/zhangyanxiao/HexTurnRGB
从远程仓库pull,获取远程仓库的文件到本地仓库(往GitHub上提交东西的时候,会因为远程上有东西更新了但是本地仓库没有更新而造成提交失败,所以我们在push之前,都会pull一遍)
gonganxinxideiMac-2:HexTurnRGB——Demo gonganxinxi$ git pull origin master
会出现以下界面:在这里面可以写pull的原因注释。用法可参照cocoapods导入第三方库的使用。

最后一步,将代码由本地仓库上传到Github远程仓库(此处,可能我们会查看当前是否在master,使用命令:git check master)
gonganxinxideiMac-2:HexTurnRGB——Demo gonganxinxi$ git push -u origin master

哈哈,完成了呢,看图,快
配置github的SSH key及GitHub项目上传方式一——使用终端命令行的更多相关文章
- github上传文件的几句命令行
1.首先进入要上传的本地目录,右键打开git命令行. 2.执行指令:git init 初始化本地仓库,这是会看到多了一个.git文件夹(如果没看到那就是电脑隐藏了). 3.执行命令:git ad ...
- 配置GitHub的SSH key
配置GitHub的SSH key 生成密钥对 打开git bash工具(Windows环境),Linux则直接打开命令行,执行下面的命令生成密钥文件 ssh-Keygen -t rsa -C &quo ...
- GitHub的SSH key配置以及常用的git命令介绍
一. GitHub的SSH key配置 (以windows为例,Mac iOS系统类似) SSH Key 是一种方法来确定受信任的计算机,从而实现免密码登录.Git是分布式的代码管理工具,远程的代码管 ...
- 【Linux】配置SSH Key到GitHub/GitLab
Linux配置SSH Key到GitHub/GitLab 准备工作 首先检查下本机是否已经安装了SSH,在终端输入ssh即可: 如果没有安装进行yum安装 # yum -y install opens ...
- 如何给 GitHub 添加 SSH key, 如何生成 SSH key 详细图文教程!
如何给 GitHub 添加 SSH key, 如何生成 SSH key 详细图文教程! 一. 生成 SSH key https://ide.c9.io/xgqfrms/ 创建一个空项目:(或使用 ...
- windows系统如何添加ssh key到github
我自己的电脑安装了git后,从来没有用过,今天偶然用了一次,发现不能pull到东西,报错说我没有权限,于是我网上搜索了一下,应该是我没有配置ssh key的原因,相信很多人都有和我一样的经历吧,这里呢 ...
- git ssh key for github
第一:检查.ssh是否存在(ls -al ~/.ssh) $ ls -al ~/.ssh Lists the files in your .ssh directory, if they exist 第 ...
- github 添加 SSH key
在 github 上添加 SSH key 的步骤: 1.首先需要检查你电脑是否已经有 SSH key 运行 git Bash 客户端,输入如下代码: $ cd ~/.ssh $ ls 这两个命令就是检 ...
- github添加ssh key报错Key is invalid. Ensure you've copied the file correctly
github添加ssh key的时候报错:Key is invalid. Ensure you've copied the file correctly 将秘钥复制粘贴到文本编辑器中,再粘贴复制到
随机推荐
- 问答项目---金币经验奖励规则及网站配置写入config文件
具体步骤: 引入配置文件——>获取当前数组——>进行合并 public function edit(){ //引入 config.php配置文件 $file = APP_PATH.'Com ...
- Vue 学习顺序
起步: 1.扎实的 JavaScript / HTML / CSS 基本功,ES6 最好过一遍 2.通读官方教程 (guide) 的基础篇.不要用任何构建工具,就只用最简单的 <script&g ...
- TFS二次开发01——TeamProjectsPicher
作为TFS的二次开发,首先要做的第一件工作是怎样连接到TFS并选择我们要下载的项目. 本文就此介绍一下使用TeamProjectsPicher 连接到TFS服务器. 添加引用 Microsoft.Te ...
- 小米范工具系列之十:小米范SSH批量命令执行工具
小米范SSH批量命令执行工具的主要功能是自动登录多台机器,并执行指定的命令,比如批量抓取shadow.批量获取系统版本.或者做基线时批量抓取配置等. 此工具使用java 1.8以上版本运行. 界面如下 ...
- oracle基于3种方法的大数据量插入更新
过程插入更新的3种方法: a.逐条检查插入或更新,同时执行插入或更新 b.逐条merge into(逐条是为了记录过程日志与错误信息) c.基于关联数组的检查插入.更新,通过forall批量sql执行 ...
- 006-markdown基础语法
1.标题 # 这是一级标题 ## 这是二级标题 ### 这是三级标题 #### 这是四级标题 ##### 这是五级标题 ###### 这是六级标题 2.字体 *这是倾斜的文字* **这是加粗的文字** ...
- 三、Mosquitto Java 客户端实现
本文的实现是在 << 一.Mosquitto 介绍&安装>> << 二. Mosquitto 的使用说明 >> 两篇文章搭建好 Mosquitt ...
- Mybatis的CRUD案例
一.Mybatis增删改查案例 上一节<Mybatis入门和简单Demo>讲了如何Mybatis的由来,工作流程和一个简单的插入案例,本节主要继上一讲完整的展示Mybatis的CRUD操作 ...
- xml转为array
PHP实现微信支付,微信支付宝返回的xml结果如下: <xml> <appid><![CDATA[wx2421b1c4370ec43b]]></appid ...
- Codeforces Round #532 (Div. 2) Solution
A. Roman and Browser 签到. #include <bits/stdc++.h> using namespace std; ]; int get(int b) { ]; ...