github使用教程
<div><div>
<h2>创建github项目</h2>
<p>首先我们进入github官网:github,注册一个用户Sign up,这里就不教大家怎么注册了,你自己起个用户名(得是英文),再用你的邮箱地址作为账号,密码一设,注册结束,然后Sign in登录,登录后如图:</p>
<div class="image-package">
<div class="image-container">
<div class="image-container-fill"> </div>
<div class="image-view" data-width="1328" data-height="600"><img src="//upload-images.jianshu.io/upload_images/4645892-125627db92cd278d.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp"></div>
</div>
<div class="image-caption"> </div>
</div>
<p>点击start a project(开始一个项目),如图:</p>
<div class="image-package">
<div class="image-container">
<div class="image-container-fill"> </div>
<div class="image-view" data-width="1351" data-height="686"><img src="//upload-images.jianshu.io/upload_images/4645892-fa3717f1a74553f7.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp"></div>
</div>
<div class="image-caption"> </div>
</div>
<p>进行相关信息的填写信息,由于是英语这里简单说说:</p>
<blockquote>
<p><code>Repository name</code>(库名称):填写你要创建的git项目的名字<br>
<code>Description (optional)</code> :填写你的项目的规范<br>
<code>Public Initialize this repository with a README</code>:初始化本库,可选择可不选择,这里分为两种演示方式,先演示不选择的。</p>
</blockquote>
<h2>git本地化</h2>
<h4>本地化方式一</h4>
<p>点击<code>Create repository</code>,创建库,如果不选中<code>Initialize this repository with a README</code>,创建后如图:</p>
<div class="image-package">
<div class="image-container">
<div class="image-container-fill"> </div>
<div class="image-view" data-width="1351" data-height="686"><img src="//upload-images.jianshu.io/upload_images/4645892-06fcbf8f7941e7e6.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp"></div>
</div>
<div class="image-caption"> </div>
</div>
<p>不了解的人看到这个就不能理解了,这是什么?不急,按照下面的教程,你的疑问会慢慢进行解答</p>
<h6>新建文件夹存放git</h6>
<p>其实这就到了命令初始化git了,如果你是window用户的话,自行创建一个文件夹,然后shift+右键,选中"在这里打开命令行",然后跳过linux建目录的过程。</p>
<p>如果你是linux的话,要么自行定义文件夹,要么按照流程跟我走,我们打开命令行,linux如下:</p>
<pre class="hljs bash"><code class="bash"><span class="hljs-built_in">cd ~
mkdir githubproject(文件夹名)
<span class="hljs-built_in">cd githubproject/
</span></span></code></pre>
<p>首先到达home目录,创建一个文件夹名叫githubproject,再进入到文件夹里面。</p>
<h6>命令创建git分支</h6>
<blockquote>
<p>提示:这里window用户请使用git带的git base</p>
</blockquote>
<p>在创建库时,他会给以提示,如上面的图片,然后你照着页面上的命令一行一行的往下输:</p>
<pre class="hljs bash"><code class="bash"><span class="hljs-built_in">echo <span class="hljs-string">"# -git-" >> README.md (说明:<span class="hljs-built_in">echo <span class="hljs-string">"# 这里是你要创建的git项目的名字")
</span></span></span></span></code></pre>
<p>输入完成打开文件则有一个叫README.md的文件,如图:</p>
<div class="image-package">
<div class="image-container">
<div class="image-container-fill"> </div>
<div class="image-view" data-width="890" data-height="597"><img src="//upload-images.jianshu.io/upload_images/4645892-62edd74c4c33f9c5.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/890/format/webp"></div>
</div>
<div class="image-caption"> </div>
</div>
<p>再输入</p>
<pre class="hljs undefined"><code>git init
</code></pre>
<p>初始化一个git,初始完git后,如果你是window用户,你会在目录里看到一个<code>.git</code>文件夹,这就说明本地初始化git成功了,然后输入</p>
<pre class="hljs css"><code class="css"><span class="hljs-selector-tag">git <span class="hljs-selector-tag">add <span class="hljs-selector-tag">README<span class="hljs-selector-class">.md
</span></span></span></span></code></pre>
<p>给git添加文件README.md,添加完以后,需要进行托付,并写明托付原因:</p>
<pre class="hljs bash"><code class="bash">git commit -m <span class="hljs-string">"first commit"
</span></code></pre>
<p>其中-m后面的"first commit"就是你要写的托付原因,当然也是支持汉语的。接下来就是,添加远程仓库:(注意后面的链接是你创建github项目时,自动生成的)</p>
<pre class="hljs cpp"><code class="cpp">git remote add origin https:<span class="hljs-comment">//github.com/nongshuqiner/-git-.git
</span></code></pre>
<p>添加完远程仓库分支后,接下来就是提交这个分支了:</p>
<pre class="hljs undefined"><code>git push -u origin master
</code></pre>
<p>提交的时候会要求你输入你的帐号和密码,如果没有要求也无关紧要,输入完成以后到我们的项目里看,它就创建成功了,如图:</p>
<div class="image-package">
<div class="image-container">
<div class="image-container-fill"> </div>
<div class="image-view" data-width="1351" data-height="686"><img src="//upload-images.jianshu.io/upload_images/4645892-33ba4237238d8b62.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp"></div>
</div>
<div class="image-caption"> </div>
</div>
<blockquote>
<p>这种方式,是先初始化本地git,再把git提交成远程分支的,接下来我们来看另外一种本地化方式。</p>
</blockquote>
<h4>本地化方式二</h4>
<p>如果我们当时选中<code>Initialize this repository with a README(初始化本库)</code>,如图</p>
<div class="image-package">
<div class="image-container">
<div class="image-container-fill"> </div>
<div class="image-view" data-width="1351" data-height="686"><img src="//upload-images.jianshu.io/upload_images/4645892-ae0d8a92c5e2081f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp"></div>
</div>
<div class="image-caption"> </div>
</div>
<p>则是另外一种方式,他会直接先把远程库创建好,如图:</p>
<div class="image-package">
<div class="image-container">
<div class="image-container-fill"> </div>
<div class="image-view" data-width="1351" data-height="686"><img src="//upload-images.jianshu.io/upload_images/4645892-a853dc29d0e4034f.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1000/format/webp"></div>
</div>
<div class="image-caption"> </div>
</div>
<p>我们则需要把这个远程库拉到本地就可以了。点击绿色按钮clone or download,如图:</p>
<div class="image-package">
<div class="image-container">
<div class="image-container-fill"> </div>
<div class="image-view" data-width="453" data-height="277"><img src="//upload-images.jianshu.io/upload_images/4645892-02d63695ea24082b.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/453/format/webp"></div>
</div>
<div class="image-caption"> </div>
</div>
<p>复制里面的链接,我们再次打开命令行,linux如下:(window请打开<code>Git bBash Here</code>)</p>
<pre class="hljs bash"><code class="bash"><span class="hljs-built_in">cd ~
mkdir gitproject(文件夹名)
<span class="hljs-built_in">cd gitproject/
</span></span></code></pre>
<p>首先到达home目录,创建一个文件夹名叫gitproject,再进入到文件夹里面。</p>
<p>然后使用clone命令,从远程库拉一个分支:</p>
<pre class="hljs php"><code class="php">git <span class="hljs-keyword">clone https:<span class="hljs-comment">//github.com/nongshuqiner/playgit.git
</span></span></code></pre>
<p>然后添加文件:</p>
<pre class="hljs undefined"><code>git add .
</code></pre>
<p>给git添加文件之后就和上面的步骤相同了,添加完以后,就该写托付,并写明托付原因:</p>
<pre class="hljs undefined"><code>git commit -a
</code></pre>
<p>这里使用-a来,当然上面的<code>git commit -m "first commit"</code>也是可以的。</p>
<p>最后<code>git push</code>,进行推送提交。</p>
<blockquote>
<p>这里的本地化方式是先创建远程分支,再下拉到本地的。这里两种本地化方式都介绍完毕,下来就是一些常用操作的说明。</p>
</blockquote>
<h2>git常用的命令行操作说明:</h2>
<p>接下来就是我们项目常用的一些操作说明了,如果我们在git目录中,修改或添加文件时,git会进行相应的记录,我们可以通过<code>git status</code>来进行查看,比如我在git里面添加了一些文件,然后在项目目录里打开命令行,输入<code>git status</code>,你会发现命令行会提示你,你添加了哪些东西,如图:</p>
<div class="image-package">
<div class="image-container">
<div class="image-container-fill"> </div>
<div class="image-view" data-width="799" data-height="476"><img src="//upload-images.jianshu.io/upload_images/4645892-3025294dd2c13013.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/799/format/webp"></div>
</div>
<div class="image-caption"> </div>
</div>
<p>你可以看到,你提交的时候它会给你进行提示:修改尚未加入提交(使用 "git add" 和/或 "git commit -a")</p>
<p>如果你只是修改文件则直接:<code>git commit -a</code>,然后自动进入vim编辑器,你在英文输入法下按<code>i</code>键,然后在最上面一栏输入提交的内容(随便说说你都干了什么),然后<code>esc</code>,英文输入法下:<code>shift+:</code>输入<code>wq</code>(w保存,q退出),就可以了。</p>
<p>如果你有添加新文件,则在<code>git commit -a</code>之前添加一句<code>git add -A</code>就可以了,意思是添加所有的文件(包含你新添加的文件)到git版本控制器。</p>
<p>提交了项目,下来就是把信息推送到<code>git</code>分支上了,直接输入:<code>git push</code> 就可以了。</p>
<p>如果有其他人在分支上修改了东西,你需要把最新的git信息拉到你的本地git,这时你也只需要在你的项目文件里打开命令行,直接输入<code>git pull</code>就可以了。</p>
</div>
<br><br></div>
<p> </p><br><br>
来源:https://www.cnblogs.com/yiluxiangbeis/p/10890607.html
頁:
[1]