<body>
<div class="scrollblock block-title">
<p>助你开始使用 git 的简易指南,木有高深内容,;)。</p>
<a href="https://twitter.com/share" class="twitter-share-button" data-via="rogerdudler" data-size="large" data-url="http://rogerdudler.github.com/git-guide" data-related="rogerdudler" data-hashtags="git">Tweet</a>
<p class="meta">
作者:<a href="http://www.twitter.com/rogerdudler">罗杰·杜德勒</a>
<br>感谢:<a href="http://www.twitter.com/tfnico">@tfnico</a>, <a href="http://www.twitter.com/fhd">@fhd</a> and <a href="http://www.namics.com/">Namics</a><br>
其他语言
<a href="https://www.bootcss.com/p/git-guide/index.html">english</a>,
<a href="https://www.bootcss.com/p/git-guide/index.de.html">deutsch</a>,
<a href="https://www.bootcss.com/p/git-guide/index.es.html">español</a>,
<a href="https://www.bootcss.com/p/git-guide/index.fr.html">français</a>,
<a href="https://www.bootcss.com/p/git-guide/index.it.html">italiano</a>,
<a href="https://www.bootcss.com/p/git-guide/index.nl.html">nederlands</a>,
<a href="https://www.bootcss.com/p/git-guide/index.pt_BR.html">português</a>,
<a href="https://www.bootcss.com/p/git-guide/index.ru.html">русский</a>,
<a href="https://www.bootcss.com/p/git-guide/index.tr.html">türkçe</a>,
<br>
<a href="https://www.bootcss.com/p/git-guide/index.my.html">မြန်မာ</a>,
<a href="https://www.bootcss.com/p/git-guide/index.ja.html">日本語</a>,
<a href="https://www.bootcss.com/p/git-guide/index.ko.html">한국어</a>
<br>
如有纰漏,请到 <a href="https://github.com/rogerdudler/git-guide/issues">github</a> 填报
</p>
<img src="./git 使用简易指南_files/arrow.png" alt="">
</div>
<!-- setup -->
<a name="setup"></a>
<div class="scrollblock block-setup">
<h2>安装</h2>
<p>
<a href="http://code.google.com/p/git-osx-installer/downloads/list?can=3">下载 git OSX 版</a>
</p>
<p>
<a href="http://code.google.com/p/msysgit/downloads/list?can=3">下载 git Windows 版</a>
</p>
<p>
<a href="http://book.git-scm.com/2_installing_git.html">下载 git Linux 版</a>
</p>
</div>
<a name="create"></a>
<div class="scrollblock block-create">
<h2>创建新仓库</h2>
<p>
创建新文件夹,打开,然后执行 <br>
<code>git init</code><br>
以创建新的 git 仓库。
</p>
</div>
<a name="checkout"></a>
<div class="scrollblock block-checkout">
<h2>检出仓库</h2>
<p>
执行如下命令以创建一个本地仓库的克隆版本:<br>
<code>git clone /path/to/repository</code> <br>
如果是远端服务器上的仓库,你的命令会是这个样子:<br>
<code>git clone username@host:/path/to/repository</code>
</p>
</div>
<a name="trees"></a>
<div class="scrollblock block-trees">
<h2>工作流</h2>
<p>
你的本地仓库由 git 维护的三棵“树”组成。第一个是你的 <code>工作目录</code>,它持有实际文件;第二个是 <code>缓存区(Index)</code>,它像个缓存区域,临时保存你的改动;最后是 <code>HEAD</code>,指向你最近一次提交后的结果。
</p>
<img src="https://img2018.cnblogs.com/blog/1737237/201907/1737237-20190711172811979-1909691250.png">
</div>
<a name="add"></a>
<div class="scrollblock block-add">
<h2>添加与提交</h2>
<p>
你可以计划改动(把它们添加到缓存区),使用如下命令:<br>
<code>git add <filename></code><br>
<code>git add *</code><br>
这是 git 基本工作流程的第一步;使用如下命令以实际提交改动:<br>
<code>git commit -m "代码提交信息"</code><br>
现在,你的改动已经提交到了 <b>HEAD</b>,但是还没到你的远端仓库。
</p>
</div>
<a name="push"></a>
<div class="scrollblock block-remote">
<h2>推送改动</h2>
<p>
你的改动现在已经在本地仓库的 <b>HEAD</b> 中了。执行如下命令以将这些改动提交到远端仓库:<br>
<code>git push origin master</code><br>
可以把 <i>master</i> 换成你想要推送的任何分支。
<br><br>
如果你还没有克隆现有仓库,并欲将你的仓库连接到某个远程服务器,你可以使用如下命令添加:<br>
<code>git remote add origin <server></code><br>
如此你就能够将你的改动推送到所添加的服务器上去了。<br>