配置SSH keys并且通过命令行将本地代码上传至GitHub

1.创建SSH KEY

Administrator@NZLO8670LSQ7S0Y MINGW64 ~/Desktop
$ mkdir .ssh

Administrator@NZLO8670LSQ7S0Y MINGW64 ~/Desktop
$ cd .ssh

Administrator@NZLO8670LSQ7S0Y MINGW64 ~/Desktop/.ssh
$ ssh-Keygen -t rsa -C "GitHub邮箱"

输入完成之后一直按回车键 中间会提示你要输入文件、密码,不用管一直按回车直到出现以下信息:

Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/Administrator/.ssh/id_rsa):
Created directory '/c/Users/Administrator/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/Administrator/.ssh/id_rsa
Your public key has been saved in /c/Users/Administrator/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:BjHeXPjgR9D5QDiki9HUWdCANOcpTQWGIsU7SjKOGiY 
The key's randomart image is:
+---[RSA 3072]----+
|   o..*=X#=.     |
|  . o+o&Bo*      |
|   ..o*.*= o     |
|o . oo +. o .    |
|o+ .... S.       |
|Eo.    .         |
|+.               |
|.                |
|                 |
+----[SHA256]-----+

2.登录GitHub添加SSH

登录Github,找到右上角的图标,打开点进里面的Settings,再选中里面的SSH and GPG KEYS,点击右上角的New SSH key,然后Title里面随便填,再把刚才id_rsa.pub里面的内容复制到Title下面的Key内容框里面,最后点击Add SSH key,这样就完成了SSH Key的加密。具体步骤也可看下面:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

3.4、回到终端,进行SSH确认连接

ssh -T Git@github.com

执行完这条指令之后会输出 Are you sure you want to continue connecting (yes/no)? 输入 yes 回车
出现以下的问题:
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).

4.设置username和email

Administrator@NZLO8670LSQ7S0Y MINGW64 ~/Desktop
$ git config --global user.nam "GitHub用户名"

Administrator@NZLO8670LSQ7S0Y MINGW64 ~/Desktop
$ git config --global user.email "GitHub邮箱"
cd到你的本地项目、根目录下,再执行git命令

5.git本地仓库初始化

这个时候可以在我们的项目文件中看到.git文件夹了

Administrator@NZLO8670LSQ7S0Y MINGW64 /f/jupyter-notebook-workspace (master)
$ git init

出现以下错误:

opened by 'git commit'. Please make sure all processes
are terminated then try again. If it still fails, a git process
may have crashed in this repository earlier:
remove the file manually to continue.

进入项目文件夹下的 .git文件中(显示隐藏文件夹或rm .git/index.lock)删除index.lock文件即可

6.将本地项目的所有文件添加到暂存区中

Administrator@NZLO8670LSQ7S0Y MINGW64 /f/jupyter-notebook-workspace (master)
$ git add .

7.将暂存区的文件提交到git本地仓库

命令:git commit -m “first commit” 双引号里面写注释语句

Administrator@NZLO8670LSQ7S0Y MINGW64 /f/jupyter-notebook-workspace (master)
$ git commit -m "first commit"

8.将本地仓库关联到Github上

Administrator@NZLO8670LSQ7S0Y MINGW64 /f/jupyter-notebook-workspace/tensorflow (master)
$ git remote add origin https://github.com/kathryn1108/machine-deep-learning

从远程仓库pull,获取远程仓库的文件到本地仓库(往GitHub上提交东西的时候,会因为远程上有东西更新了但是本地仓库没有更新而造成提交失败,所以我们在push之前,都会pull一遍)

Administrator@NZLO8670LSQ7S0Y MINGW64 /f/jupyter-notebook-workspace/tensorflow (master)
$ git pull origin master
Administrator@NZLO8670LSQ7S0Y MINGW64 /f/jupyter-notebook-workspace/tensorflow (master)
$ git push -u origin master
Error: failed to push some refs to

push时可能出现以下错误,这是因为github中的README.md文件不在本地代码目录中

error: failed to push some refs to 'https://github.com/kathryn1108/data'
hint: Updates were rejected because the tip of your current branch is behind
hint: its remote counterpart. Integrate the remote changes (e.g.
hint: 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

所以通过以下命令将README.md文件pull到本地,然后再push

git pull --rebase origin master
Error:Please enter a commit message to explain why this merge is necessary

在这里插入图片描述
git 在pull或者合并分支的时候有时会遇到这个界面。如果要输入解释的话就需要:
1.按键盘字母 i 进入insert模式
2.修改最上面那行黄色合并信息,可以不修改
3.按键盘左上角"Esc"
4.输入":wq",注意是冒号+wq,按回车键即可( :wq 强制性写入文件并退出,即使文件没有被修改也强制写入,并更新文件的修改时间)
也可以忽略1,2直接跳到第3,4步

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值