🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# hexo+Github免费搭建个人博客(一):git连接GitHub [toc] ## 准备工作 1. 注册一个GitHub账号[GitHub官网](https://github.com/) 2. nodejs安装包[nodejs官网下载](http://nodejs.cn/download/) 3. git下载[git官网下载](https://git-scm.com/downloads) 4. notepad++[notepad++官网下载](https://notepad-plus-plus.org/downloads/) ## 工具用途 1. Github账号:是存储自己网页的储存库(类似于一个服务器) 2. nodejs:是用于hexo环境搭建的,主要是用其**npm**命令来下载hexo所需要的资源包 3. git:用于连接GitHub,将本地的hexo生成的静态网页,直接上传到GitHub上完成部署 ## git连接GitHub ### 安装git 1.双击软件包,打开下面页面,点击**Next**按钮,进入下一步 ![](https://imgkr.cn-bj.ufileos.com/ad442c37-55f0-409f-82d0-9f91636e5fe0.png) 2.选择安装路径,点击**Next**按钮,进入下一步 ![](https://imgkr.cn-bj.ufileos.com/a631ce89-1605-490d-aa61-ec0b460af1d3.png) 3.不会选择,默认即可,图片下面有注释,点击**Next**按钮,进入下一步 ![](https://imgkr.cn-bj.ufileos.com/bc211a89-3255-4e7e-b4e2-de24d5213e71.png) > **Additional icons**: 附加图标 > > **On the Desktop**: 在桌面上 > > **Windows Explorer integration Windows**:资源管理器集成鼠标右键菜单 >> **Git Bash Here** >> >> **Git GUI Here** > > **Git LFS (Large File Support)**: 大文件支持 > > **Associate .git* configuration files with the default text editor**: 将 .git 配置文件与默认文本编辑器相关联 > > **Associate .sh files to be run with Bash**: 将.sh文件关联到Bash运行 > > **Use a TrueType font in all console windows**: 在所有控制台窗口中使用TrueType字体 > > **Check daily for Git for Windows updates** 每天检查Git是否有Windows更新 4.不用动,点击**Next**按钮,进入下一步 ![](https://imgkr.cn-bj.ufileos.com/4f1f688b-7ed5-42a6-b29b-4a676d7d25bd.png) 5.默认即可,点击**Next**按钮,进入下一步 ![](https://imgkr.cn-bj.ufileos.com/af866440-036f-4125-ac77-5cc978e3d494.png) >**Use the Nano editor by default**: 默认使用 Nano 编辑器 > >**Use Vim (The ubiquitous text editor) as Git's default editor**: 使用 Vim 作为 Git 的默认编辑器 > >**Use Notepad++ as Git's default editor**: 使用 Notepad++ 作为 Git 的默认编辑器 > >**Use Visual Studio Code as Git's default editor**: 使用 Visual Studio Code 作为Git 的默认编辑器 > >**Use Visual Studio Code Insiders as Git's default editor**: 使用Visual Studio Code Insiders 作为 Git 的默认编辑器 6.配置path变量,选择**Git from the command line and also from 3rd-party software**,点击**Next**按钮,进入下一步 ![](https://imgkr.cn-bj.ufileos.com/8ef71ad3-af5f-4853-8101-d905818bf060.png) >**Use Git from Git Bash only** >>This is the safest choice as your PATH will not be modified at all.You will only be able to use the Git command line tools form Git Bash. >> >>这是最安全的选择,因为您的PATH根本不会被修改。您只能使用 Git Bash 的 Git 命令行工具。 > >**Git from the command line and also from 3rd-party software** >>(Recommended)This option adds only some minimal Git wrappers to your PATH to avoid cluttering your environment with optional Unix tools. You will be able to use Git from Git Bash,the Command Prompt and the Windows PowerShell as well as any third-party software looking for Git in PATH. >> >>(推荐)此选项仅将一些最小的Git包装器添加到PATH中,以避免使用可选的Unix工具使环境混乱。 >> >>您将能够使用Git Bash中的Git,命令提示符和Windows PowerShell以及在PATH中寻找Git的任何第三方软件。 > >**Use Git and optional Unix tools from the Command Prompt** > >从Windows命令提示符使用Git和可选的Unix工具 >>Both Git and the optional Unix tools will be added to you PATH >> >>Git和可选的Unix工具都将添加到您计算机的 PATH 中 >> >>Warning:This will override Windows tools like "find and sort".Only use this option if you understand the implications. >> >>警告:这将覆盖Windows工具,如 “ find 和 sort ”。只有在了解其含义后才使用此选项。 7.选择**Use the OpenSSL library**,点击**Next**按钮,进入下一步 ![](https://imgkr.cn-bj.ufileos.com/8ded1ac3-588f-4193-a26b-099e4682cbe6.png) >**Use the OpenSSL library** > >使用 OpenSSL 库 >>Server certificates will be validated using the ca-bundle.crt file. >> >>服务器证书将使用ca-bundle.crt文件进行验证。 > >**Use the native Windows Secure Channel library** > >使用本地 Windows 安全通道库 >>Server certificates will be validated using Windows Certificate Stores.This option also allows you to use your company's internal Root CA certificates distributed e.g. via Active Directory Domain Services. >> >>服务器证书将使用Windows证书存储验证。此选项还允许您使用公司的内部根CA证书,例如, 通过Active Directory Domain Services 。 8.选择**Checkout Windows-style,commit Unix-style line endings**,点击**Next**按钮,进入下一步 ![](https://imgkr.cn-bj.ufileos.com/f7d6447d-3695-4093-ac8b-381f41819a16.png) >**Checkout Windows-style,commit Unix-style line endings** >>Git will convert LF to CRLF when checking out text files.When committing text files,CRLF will be converted to LF .For cross-pltform projects,this is the recommended setting on Windows ("core.autocrlf" is set to "true") >> >>在检出文本文件时,Git会将LF转换为CRLF。当提交文本文件时,CRLF将转换为LF。 对于跨平台项目,这是Windows上推荐的设置(“core.autocrlf”设置为“true”) > >**Checkout as-is , commit Unix-style line endings** >>Git will not perform any conversion when checking out text files. When committing text files, CRLF will be converted to LF. For cross-platform projects,this is the recommended setting on Unix ("core.autocrlf" is set to "input") >> >>在检出文本文件时,Git不会执行任何转换。 提交文本文件时,CRLF将转换为LF。 对于跨平台项目,这是Unix上的推荐设置 (“core.autocrlf”设置为“input”) > >**Checkout as-is,commit as-is** >>Git will not perform any conversions when checking out or committing text files.Choosing this option is not recommended for cross-platform projects ("core.autocrlf"is set to "false") >> >>在检出或提交文本文件时,Git不会执行任何转换。对于跨平台项目,不推荐使用此选项(“core.autocrlf”设置为“false”) 9.选择**Use MinTTY (the default terminal of MSYS2)**,点击**Next**按钮,进入下一步 ![](https://imgkr.cn-bj.ufileos.com/b21ae4a9-188e-4f70-8782-ba2b8ea811cf.png) >**Use MinTTY (the default terminal of MSYS2)** >>Git Bash will use MinTTY as terminal emulator,which sports a resizable window,non-rectangular selections and a Unicode font. Windows console programs (such as interactive Python) must be launched via 'winpty' to work in MinTTY. >> >>Git Bash将使用MinTTY作为终端模拟器,该模拟器具有可调整大小的窗口,非矩形选区和Unicode字体。 Windows控制台程序(如交互式Python)必须通过'winpty'启动才能在MinTTY中运行。 > >**Use Windows' default console window** >>Git will use the default console window of Windows ("cmd.exe"),which works well with Win32 console programs such as interactive Python or node.js , but has a very limited default scroll-back,needs to be configured to use aUnicode font in order to display non-ASCII characters correctly,and prior to Windows 10 its windows was not freely resizable and it only allowed rectangular text selections. >> >>Git将使用Windows的默认控制台窗口(“cmd.exe”),该窗口可以与Win32控制台程序(如交互式Python或node.js)一起使用,但默认的回滚非常有限,需要配置为使用unicode 字体以正确显示非ASCII字符,并且在Windows 10之前,其窗口不能自由调整大小,并且只允许矩形文本选择。 10.选择默认选项,点击**Install**按钮,开始安装 ![](https://imgkr.cn-bj.ufileos.com/66b85c82-f540-444a-bf9d-87656d10434f.png) >**Enable file system caching**<br> >启用文件系统缓存 >>File system data will be read in bulk and cached in memory for certain operations ("core.fscache" is set to "true"). This provides a significant performance boost.<br> >>文件系统数据将被批量读取并缓存在内存中用于某些操作(“core.fscache”设置为“true”)。 这提供了显着的性能提升。 > >**Enable Git Credential Manager**<br> >启用Git凭证管理器 >>The Git Credential Manager for Windows provides secure Git credential storage for Windows,most notably multi-factor authentication support for Visual Studio Team Services and GitHub. (requires .NET framework v4.5.1 or or later).<br> >>Windows的Git凭证管理器为Windows提供安全的Git凭证存储,最显着的是对Visual Studio Team Services和GitHub的多因素身份验证支持。 (需要.NET Framework v4.5.1或更高版本)。 > >**Enable symbolic links**<br> >启用符号链接 >>Enable symbolic links (requires the SeCreateSymbolicLink permission).Please note that existing repositories are unaffected by this setting.<br> >>启用符号链接(需要SeCreateSymbolicLink权限)。请注意,现有存储库不受此设置的影响。 11.安装进行中,如下图所示 ![](https://imgkr.cn-bj.ufileos.com/65c4e2b2-9e5a-4d81-af25-4de2ebe02cc2.png) 12.安装成功![](https://res.smzdm.com/images/emotions/64.png) ![](https://imgkr.cn-bj.ufileos.com/a1e01445-e106-4219-9eb6-991cc5d0fe3b.png) ### 创建ssh key 1. 设置自己的username和email(github和gitee会记录的) - 在Windows桌面**右击**打开**Git Bash Here**,一行命令回车一次 ![](https://imgkr.cn-bj.ufileos.com/7ee100b1-8c30-4802-b5a1-d535581bfd97.png) ``` powershell git config --global user.name "itxh" git config --global user.email "892457803@qq.com" ``` ![](https://imgkr.cn-bj.ufileos.com/f4fbeedf-0b27-4d3e-abeb-a17198c34a8a.png) 2. 创建ssh key(换成自己的) ``` powershell ssh-keygen -t rsa -C "892457803@qq.com" ``` 有要输入的地方,回车就行 成功后会在windows的**用户文件夹**下创建一个.ssh文件夹,里面有一个**id_rsa.pub**文件,复制里面的内容 用一下命令来查看**id_rsa.pub**里面的内容 ![](https://imgkr.cn-bj.ufileos.com/29bc4388-c8d0-4cad-bfee-b0ee3d70b787.png) ``` powershell cat .ssh/id_rsa.pub ``` ![](https://imgkr.cn-bj.ufileos.com/1fee710c-732b-4e89-bc2a-7ae1000d6b93.png) 3. 给GitHub添加公钥 - 登录GitHub,点击**头像**,点击**Settings** ![](https://imgkr.cn-bj.ufileos.com/f7b32a5d-c582-46bb-9b4e-7f891ee48912.png) - 点击**SSH and GPG keys**,再点击*New SSH key**,标题随便起,**key**添加**id_rsa.pub**里面的内容,点击**Add SSH key**按钮,即可添加成功。 ![](https://imgkr.cn-bj.ufileos.com/4e80bfde-7c61-4d69-976d-c427d9038e75.png) ### 检验是否连接成功 #### Github检验,出现你的姓名,表示连接成功 - 出现输入的地方,输入**yes**即可 ```powershell ssh -T git@github.com ``` ![](https://imgkr.cn-bj.ufileos.com/3b8311d1-fc15-4443-8979-1cdf9d1cf881.png) ## 本人搭建环境(亲测,没问题) - win7 - win10 - mac