git和github新手安装使用教程(三步入门)
<p>git和github新手安装使用教程(三步入门)</p><p>对于新手来说,每次更换设备时,github的安装和配置都会耗费大量时间。主要原因是每次安装时都只关心了【怎么做】,而忘记了记住【为什么】。本文从操作的原因入手,将github的安装和配置分为了三个步骤,再细分成各个小步骤,方便大家形成形象记忆,早日脱离该教程的帮助。</p>
<hr>
<p> </p>
<p>使用github只需要简单的三步:</p>
<p> 一:初始化本地仓库git</p>
<p> 二:将自己的电脑与指定github账户关联</p>
<p> 三:将自己的仓库与github上的某个项目关联</p>
<p><strong>一:初始化本地仓库git</strong></p>
<p> 1.下载一个git吧 下载链接 ,根据提示安装git</p>
<p> 2.新建一个文件夹repo作为本地仓库,右键,选择Git Init here。<em>注意:有的版本没有git init here ,则选择git bash here ,在打开的页面中输入git init</em></p>
<p><em> 第</em>一步的结果就是:(1)在安装的时候自动配置了git运行环境。(2)通过git init 在指定文件夹生成了隐藏的 .git 文件夹。用于保存本地仓库版本的相关信息(版本信息,仓库信息,git命令编译规则等)</p>
<p><strong>二:将自己的电脑与指定github账户关联</strong></p>
<p><strong> </strong>1.创建一个github账户吧 创建地址</p>
<p> 2.在本机上设置你的github的邮箱和用户名</p>
<div class="cnblogs_code">
<pre>git config --global user.name "用户名"
git config --global user.email "邮箱"</pre>
</div>
<p> 3.生成本机的SSH key</p>
<div class="cnblogs_code">
<pre>ssh-keygen -t rsa -C "邮箱"</pre>
</div>
<p> </p>
<p> 根据提示,按三次回车键,最后会生成ssh key值,并告诉你key值存放的文件的位置,找到该文件并复制ssh key</p>
<p> 4.打开你的github主页。找到Settings,</p>
<p><img alt="" class="medium-zoom-image lazyload" data-src="https://images2018.cnblogs.com/blog/1291030/201712/1291030-20171203174623694-1361695866.png"></p>
<p> 选择SSH and GPG keys ,再选择new SSH key,title 随意填,key值就是刚刚生成的本机 SSH KEY</p>
<p> <img alt="" class="medium-zoom-image lazyload" data-src="https://images2018.cnblogs.com/blog/1291030/201712/1291030-20171203174806085-452836274.png"></p>
<p> 第二步设置了本地git与github之间通信的密码,github账户只接受合法的SSH KEY 对其下项目进行修改。</p>
<p><strong>三:将自己的仓库与github上的某个项目关联</strong></p>
<p> 1.打开github主页,选择 new repository,打开新建项目页面。</p>
<p> 在新建项目页面,输入项目名称,点击下一步,复制生成项目后的项目SSH</p>
<p> 2.打开本地仓库的git bash页面。输入</p>
<div class="cnblogs_code">
<pre>git remote add origin "项目SSH"</pre>
</div>
<p> </p>
<p> 3.先同步github上master分支的代码,再指定上传的默认分支</p>
<div class="cnblogs_code">
<pre>git pull origin master
git push -u origin master</pre>
</div>
<p> </p>
<p> 第三步设置了本地仓库对应的是github账户上的哪一个项目,并且设置了代码上传的分支。注意github上的项目名称与本地仓库名称同级,也就是说,从github上同步代码时,只会更新项目名称下的各个文件到本地仓库中。</p>
<hr>
<p> 以上就是安装配置github的全部过程,以下为github最常用的命令</p>
<div class="table-wrapper">
<table>
<thead>
<tr class="header"><th align="left">编号</th><th align="left">命令</th><th align="left">备注</th></tr>
</thead>
<tbody>
<tr class="odd">
<td align="center">1</td>
<td align="left">git status</td>
<td align="left">查看仓库的改变情况,会有相关的提示操作出现</td>
</tr>
<tr class="even">
<td align="center">2</td>
<td align="left">git add -A</td>
<td align="left">直接添加所有改动的文件</td>
</tr>
<tr class="odd">
<td align="center">3</td>
<td align="left">git commit -m "note"</td>
<td align="left">确认生成本地的版本,note是 版本特点说明</td>
</tr>
<tr class="odd">
<td align="center">4</td>
<td align="left">git push</td>
<td align="left">将改动上传到github,若没有指定分支,则需要使用git push origin master</td>
</tr>
<tr class="even">
<td align="center">5</td>
<td align="left">git log</td>
<td align="left">查看版本更新情况</td>
</tr>
<tr class="odd">
<td align="center">6</td>
<td align="left">git reset -hard x</td>
<td align="left">回退到某个本地版本,x为git log中出现的hash值的前七位</td>
</tr>
<tr class="even">
<td align="center">7</td>
<td align="left">git clean -xf</td>
<td align="left">清除所有的未提交文件</td>
</tr>
</tbody>
</table>
</div>
<p> </p>
<p>先了解配置过程中的三大步骤,再记住各个细分的小步骤,就能尽早的脱离说明文档,熟练的配置和使用github,祝你不再需要这篇文章的帮助!</p>
<p> </p><br><br>
来源:https://www.cnblogs.com/wangjianyun/p/16846855.html
頁:
[1]