新手小白在github上部署一个项目

一、 注册github账号
github地址:https://www.github.com/
二、下载安装Git
地址:https://git-scm.com/downloads
安装方法详见:https://blog.csdn.net/weixin_43811057/article/details/120029031
三、准备需要上传的网页文件(项目)
新手小白在github上部署一个项目-LMLPHP
四、登录到github

然后new一个git仓库
新手小白在github上部署一个项目-LMLPHP
在Repository name下面填一个你的仓库名字,Description是描述你的仓库的这里可选。然后按照图里面的选上就可以了。之后点击Create repository。
新手小白在github上部署一个项目-LMLPHP
创建成功后如图
新手小白在github上部署一个项目-LMLPHP
然后我们点Settings进去后在左边的最下面点Pages:
新手小白在github上部署一个项目-LMLPHP
进去后在Github Pages 的设置,点击 source 中的本来的 None ,使其变成 main 分支,第二个选择root,然后点击 save。

新手小白在github上部署一个项目-LMLPHP

刷新一下页面在Gtihub Page 下面就可以看到你的github page 网址了。
新手小白在github上部署一个项目-LMLPHP


打开此电脑,选择一个盘,比如 D 盘,右键空白处点击 git bash here(前提是git已经安装好)。

按照下图输入(有时候会timeout是因为网的问题,所以多试两次)
新手小白在github上部署一个项目-LMLPHP
接下来返回电脑的D盘,我们会发现多了一个文件夹demo1,打开它后如下:
新手小白在github上部署一个项目-LMLPHP
将自己之前准备好的的网页(项目)文件复制粘贴到当前目录下也就是:D:/demo1/demo1
新手小白在github上部署一个项目-LMLPHP

返回到git bash,执行以下命令
新手小白在github上部署一个项目-LMLPHP
新手小白在github上部署一个项目-LMLPHP
新手小白在github上部署一个项目-LMLPHP
可能是我网的问题总是timeout,所以多试两次,看到有
Already uo to date. 则成功。

接下来是最后一步执行git push,稍等一会后会弹出提示框,需要输入你github的用户名(账号)和密码 (第一次操作需要)

但当我摁下回车后,不想看到一幕还是发生了,还以为账号和密码输错了。然后试了几遍还是这样。
新手小白在github上部署一个项目-LMLPHP
所以我们要仔细看一下,报错的原因

remote: Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.

它的意思是自从21年8月13后不再支持用户名密码的方式验证了,需要创建个人访问令牌(personal access token)。

这一句就是要让我们去看怎么生成这个令牌的

remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information.

生成个人令牌的官网教程:
地址:https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token

接下来我们就去生成这个令牌
进入自己的github主页点击右边的小头像,点进settings

新手小白在github上部署一个项目-LMLPHP
点击左侧的Developer settings
新手小白在github上部署一个项目-LMLPHP

进去后点Personal access tokens(个人访问令牌)
新手小白在github上部署一个项目-LMLPHP
在点Generate new token
新手小白在github上部署一个项目-LMLPHP
设置token
Note里面填个test啥的,Expriation表示这个令牌的有效时间,根据需求选择。
Select scopes
一顿乱点,先全给它选上(哈哈)。最后点击Generate token生成令牌。
新手小白在github上部署一个项目-LMLPHP
新手小白在github上部署一个项目-LMLPHP
生成成功后如图
新手小白在github上部署一个项目-LMLPHP
然后copy下来,下面要用
新手小白在github上部署一个项目-LMLPHP
其实当我仔细查看了执行过程中的代码后发现在报错中还有这一句
意思就是在git push 之前还需执行下面的命令:

git remote set-url origin  https://[email protected]/<USERNAME>/<REPO>.git

其中your_token是你的令牌(刚生成的),USERNAME是你的github用户名,REPO是你的项目名称。
比如我的

git remote set-url origin  https://[email protected]/Lang-1210/demo1.git

返回git bash,执行

git remote set-url origin https://[email protected]/Lang-1210/demo1.git
git push

新手小白在github上部署一个项目-LMLPHP
又会发现如下错误:

fatal: unable to access 'https://github.com/Lang-1210/demo1.git/': OpenSSL SSL_read: Connection was reset, errno 10054

上网查找资料得知:

  • git在拉取或者提交项目时,中间会有git的http和https代理,但是我们本地环境本身就有SSL协议了,所以取消git的https代理即可,不行再取消http的代理。
  • 服务器的SSL证书没有经过第三方机构的签署,所以才报错,解除ssl验证后,再次git**

所需执行的命令如下图:
新手小白在github上部署一个项目-LMLPHP
再次执行:git push
新手小白在github上部署一个项目-LMLPHP
成功啦!!!感觉世界么么哒。^ ^


我部署的是一个可视化大屏网页:
预览地址:https://lang-1210.github.io/demo1/page/visual.html

10-25 12:05