Git自学(2)-- Git安装后首次配置与第一次使用Git和Github管理自己的代码(超详细纯小白图文教程)
<svg xmlns="http://www.w3.org/2000/svg" style="display: none"><path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0)"></path>
</svg>
<p></p>
<div class="toc">
<h3>文章目录</h3>
<ul><li><ul><li>0、写在前面:</li><li>一、注册Github</li><li><ul><li>1、注册Github:</li><li>2、登录</li><li>3、创建仓库</li></ul>
</li><li>二、安装Git</li><li>三、配置(Git安装好后首次使用需要配置完成后才可以使用)</li><li><ul><li>1、打开Git Bash</li><li>2、显示命令行界面:</li><li>3、配置Git</li><li>4、打开GitHub,配置ssh key</li><li>5、验证配置是否成功</li><li>6、配置用户名和邮箱</li></ul>
</li><li>四、托管</li><li><ul><li>1、本地新建仓库testfirst,名字与github中的相同</li><li>2、右键目录,点击Git Bash Here,在出现的窗口输入命令 `git init`</li><li>3、注意此时计算机一定要设置显示隐藏文件,在创建的文件夹git_test下生成了一个管理git仓库的文件夹.git,里面包括所有git操作所需要的文件。</li><li>4、关联本地仓库与github仓库:</li><li>5、同步仓库到本地:</li><li>6、把本地的上传到仓库</li></ul>
</li></ul>
</li></ul>
</div>
<p></p>
<h2>0、写在前面:</h2>
<p>网上教程良莠不齐,走了很多弯路。本教程仅适合小白初次使用Git时熟悉流程和简单命令。具体管理实际项目需要学习Git命令后,我再写教程。</p>
<h2>一、注册Github</h2>
<h3>1、注册Github:</h3>
<p>官网: https://github.com/</p>
<p>记住用户名和邮箱,下面会用到。<br> <img src="https://img-blog.csdnimg.cn/20210716183559617.png" alt="在这里插入图片描述"></p>
<h3>2、登录</h3>
<p><img src="https://img-blog.csdnimg.cn/20210716183850306.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3>3、创建仓库</h3>
<p>①点击右上角的头像,再点Your repositories<br> <img src="https://img-blog.csdnimg.cn/2021071618453920.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br> ②因为是刚注册的账号,显示的是:***还没有任何公共存储库。点击绿色按钮<font color="green" size="6"> new</font>创建仓库:<br> <img src="https://img-blog.csdnimg.cn/20210716184633993.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br> ③按照图示填写仓库信息:<br> <img src="https://img-blog.csdnimg.cn/20210716185447975.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br> ④后续可以点击README.md来编辑文件。</p>
<p><img src="https://img-blog.csdnimg.cn/20210717104358875.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h2>二、安装Git</h2>
<p>Git自学(1)-- Win10 安装 Git 详细教程(超详细纯小白教程)</p>
<p>win+R打开cmd窗口,输入<code>git --version</code><br> <img src="https://img-blog.csdnimg.cn/20210716191155167.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br> 安装成功。</p>
<h2>三、配置(Git安装好后首次使用需要配置完成后才可以使用)</h2>
<h3>1、打开Git Bash</h3>
<p>在桌面上点击鼠标右键,点击Git Bash Here<br> <img src="https://img-blog.csdnimg.cn/20210716193229120.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3>2、显示命令行界面:</h3>
<p><img src="https://img-blog.csdnimg.cn/20210716193600272.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3>3、配置Git</h3>
<p>①输入 <code>ssh-keygen -t rsa -C "123456789@qq.com"</code> ,邮箱换成自己的,ssh-keygen没有空格,其他的有空格。建议直接复制我的代码。输入完成后,按Enter,此时是在①处。<br> ②此后初次出现到②,出现的是保存密钥的路径,建议默认,按Enter;<br> ③此时出现③,出现的提示是设置密码,建议不要设置!!!按Enter;<br> ④此时出现④,出现的提示是再次输入密码,不要有任何输入,继续按Enter;</p>
<p><img src="https://img-blog.csdnimg.cn/20210716194409139.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br> 打开②处的默认路径,用记事本方式打开id_rsa.pub,里面的内容是密码,下面要复制使用。<br> <img src="https://img-blog.csdnimg.cn/20210716195538479.png" alt="在这里插入图片描述"></p>
<h3>4、打开GitHub,配置ssh key</h3>
<p>点击右上角头像,再点击settings<br> <img src="https://img-blog.csdnimg.cn/20210716195904102.png" alt="在这里插入图片描述"><br> SHH and GPG keys<br> New SSH key<br> <img src="https://img-blog.csdnimg.cn/20210716200037503.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br> 按图示填入信息<br> <img src="https://img-blog.csdnimg.cn/20210716200327737.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3>5、验证配置是否成功</h3>
<p>在git bash输入命令 <code>ssh -T git@github.com</code> ,第一次配置会让你输入yes/no,输入yes。<br> <img src="https://img-blog.csdnimg.cn/20210716201323970.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br> 出现<code>You've successfully authenticated</code>,说明SSH连接正常。github上的钥匙会变成绿色。<br> <img src="https://img-blog.csdnimg.cn/20210717124009185.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<p><img src="https://img-blog.csdnimg.cn/20210716201705333.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3>6、配置用户名和邮箱</h3>
<p>在git bash输入命令:</p>
<p>用户名和邮箱改成自己的。</p>
<pre><code class="prism language-python">git config <span class="token operator">-</span><span class="token operator">-</span><span class="token keyword">global</span> user<span class="token punctuation">.</span>name <span class="token string">"用户名"</span>
</code></pre>
<pre><code class="prism language-python">git config <span class="token operator">-</span><span class="token operator">-</span><span class="token keyword">global</span> user<span class="token punctuation">.</span>email <span class="token string">"邮箱"</span>
</code></pre>
<p>如图:<br> <img src="https://img-blog.csdnimg.cn/20210716202249810.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h2>四、托管</h2>
<h3>1、本地新建仓库testfirst,名字与github中的相同</h3>
<h3>2、右键目录,点击Git Bash Here,在出现的窗口输入命令 <code>git init</code></h3>
<p><img src="https://img-blog.csdnimg.cn/20210717120324395.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<p><img src="https://img-blog.csdnimg.cn/20210717120413851.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<h3>3、注意此时计算机一定要设置显示隐藏文件,在创建的文件夹git_test下生成了一个管理git仓库的文件夹.git,里面包括所有git操作所需要的文件。</h3>
<p><img src="https://img-blog.csdnimg.cn/20210716203611283.png" alt="在这里插入图片描述"></p>
<p><img src="https://img-blog.csdnimg.cn/20210717120445967.png" alt="在这里插入图片描述"></p>
<h3>4、关联本地仓库与github仓库:</h3>
<p>命令:<code>git remote add origin git@github.com:2021AY/testfirst.git</code></p>
<p>其中2021AY是你的注册用户名,testfirst是你的仓库名。</p>
<h3>5、同步仓库到本地:</h3>
<p><code>git pull git@github.com:2021AY/testfirst.git</code></p>
<p><img src="https://img-blog.csdnimg.cn/20210717121014869.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"><br> 本地仓库中多了个文件,是原本在github上的文件。<br> <img src="https://img-blog.csdnimg.cn/20210717123500393.png" alt="在这里插入图片描述"></p>
<h3>6、把本地的上传到仓库</h3>
<p>首先在本地新建一个test.txt文件。</p>
<p><img src="https://img-blog.csdnimg.cn/20210717122132451.png" alt="在这里插入图片描述"></p>
<p>执行增加命令:<code>git add .</code> ,add后面的点,表示的是提交所有文件。如果想指定提交文件,可以写文件名。</p>
<p>执行提交命令:<code>git commit -m "第一次提交github的测试"</code> 。-m 后面是提示信息。</p>
<p>执行推送命令:<code>git push git@github.com:2021AY/testfirst.git</code></p>
<p><img src="https://img-blog.csdnimg.cn/20210717122258778.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<p>可以看到上传成功了。</p>
<p><img src="https://img-blog.csdnimg.cn/20210717122329687.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzQ2Mjc4MDM3,size_16,color_FFFFFF,t_70" alt="在这里插入图片描述"></p>
<p><img src="https://img-blog.csdnimg.cn/20210716220027442.gif#pic_center" alt="在这里插入图片描述"></p><br><br>
来源:https://www.cnblogs.com/ay2021/p/15023635.html
頁:
[1]