Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: gh-pages
Fetching contributors…

Cannot retrieve contributors at this time

229 lines (224 sloc) 11.968 kb
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>git - the simple guide - no deep shit!</title>
<link href='' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="css/normalize.css" type="text/css">
<link rel="stylesheet" href="css/style.css" type="text/css">
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-652147-13']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
function recordOutboundLink(link, category, action) {
_gat._getTrackerByName()._trackEvent(category, action);
setTimeout('document.location = "' + link.href + '"', 100);
<div class="scrollblock block-title">
<h1>git - the simple guide</h1>
<p>just a simple guide for getting started with git. no deep shit ;)</p>
<a href="" class="twitter-share-button" data-via="rogerdudler" data-size="large" data-url="" data-related="rogerdudler" data-hashtags="git">Tweet</a>
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);;js.src="//";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
<p class="meta">
by <a href="">Roger Dudler</a>
<br />credits to <a href="">@tfnico</a>, <a href="">@fhd</a> and <a href="">Namics</a><br />
this guide in <a href="">deutsch</a>, <a href="">español</a>, <a href="">français</a>, <a href="">italiano</a>, <a href="">nederlands</a>, <a href="index.pt_BR.html">português</a>, <a href="">русский</a>, <a href="index.ja.html">日本語</a><br />
please report issues on <a href="">github</a>
<img src="img/arrow.png" alt="" />
<!-- setup -->
<a name="setup"></a>
<div class="scrollblock block-setup">
<a href="">Download git for OSX</a>
<a href="">Download git for Windows</a>
<a href="">Download git for Linux</a>
<a name="create"></a>
<div class="scrollblock block-create">
<h2>create a new repository</h2>
create a new directory, open it and perform a <br />
<code>git init</code><br />
to create a new git repository.
<a name="checkout"></a>
<div class="scrollblock block-checkout">
<h2>checkout a repository</h2>
create a working copy of a local repository by running the command<br />
<code>git clone /path/to/repository</code><br />
when using a remote server, your command will be<br />
<code>git clone username@host:/path/to/repository</code>
<a name="trees"></a>
<div class="scrollblock block-trees">
your local repository consists of three "trees" maintained by git.
the first one is your <code>Working Directory</code> which holds the actual files.
the second one is the <code>Index</code> which acts as a staging area and
finally the <code>HEAD</code> which points to the last commit you've made.
<img src="img/trees.png" alt="" />
<a name="add"></a>
<div class="scrollblock block-add">
<h2>add &amp; commit</h2>
You can propose changes (add it to the <b>Index</b>) using<br />
<code>git add &lt;filename&gt;</code><br />
<code>git add *</code><br />
This is the first step in the basic git workflow. To actually commit these changes use<br />
<code>git commit -m "Commit message"</code><br />
Now the file is committed to the <b>HEAD</b>, but not in your remote repository yet.
<a name="push"></a>
<div class="scrollblock block-remote">
<h2>pushing changes</h2>
Your changes are now in the <b>HEAD</b> of your local working copy. To send those changes to your remote repository, execute <br />
<code>git push origin master</code><br />
Change <i>master</i> to whatever branch you want to push your changes to.
<br /><br />
If you have not cloned an existing repository and want to connect your repository to a remote server, you need to add it with<br />
<code>git remote add origin &lt;server&gt;</code><br />
Now you are able to push your changes to the selected remote server<br />
<a name="branching"></a>
<div class="scrollblock block-branching">
Branches are used to develop features isolated from each other. The <i>master</i> branch is the "default" branch when you create a repository. Use other branches for development and merge them back to the master branch upon completion.
<img src="img/branches.png" alt="" />
create a new branch named "feature_x" and switch to it using<br />
<code>git checkout -b feature_x</code><br />
switch back to master<br />
<code>git checkout master</code><br />
and delete the branch again<br />
<code>git branch -d feature_x</code><br />
a branch is <i>not available to others</i> unless you push the branch to your remote repository<br />
<code>git push origin &lt;branch&gt;</code>
<a name="update"></a>
<div class="scrollblock block-merging">
<h2>update &amp; merge</h2>
to update your local repository to the newest commit, execute <br />
<code>git pull</code><br />
in your working directory to <i>fetch</i> and <i>merge</i> remote changes.<br />
to merge another branch into your active branch (e.g. master), use<br />
<code>git merge &lt;branch&gt;</code><br />
in both cases git tries to auto-merge changes. Unfortunately, this is not always possible and results in <i>conflicts</i>.
You are responsible to merge those <i>conflicts</i>
manually by editing the files shown by git. After changing, you need to mark them as merged with<br />
<code>git add &lt;filename&gt;</code><br />
before merging changes, you can also preview them by using<br />
<code>git diff &lt;source_branch&gt; &lt;target_branch&gt;</code>
<a name="tagging"></a>
<div class="scrollblock block-tagging">
it's recommended to create tags for software releases. this is a known concept, which also exists in SVN. You can create a new tag named <i>1.0.0</i> by executing<br />
<code>git tag 1.0.0 1b2e1d63ff</code><br />
the <i>1b2e1d63ff</i> stands for the first 10 characters of the commit id you want to reference with your tag. You can get the commit id with <br />
<code>git log</code><br />
you can also use fewer characters of the commit id, it just has to be unique.
<a name="checkout-replace"></a>
<div class="scrollblock block-checkout-replace">
<h2>replace local changes</h2>
In case you did something wrong (which for sure never happens ;) you can replace local changes using the command<br />
<code>git checkout -- &lt;filename&gt;</code><br />
this replaces the changes in your working tree with the last content in HEAD. Changes already added to the index, as well as new files, will be kept.
If you instead want to drop all your local changes and commits, fetch the latest history from the server and point your local master branch at it like this<br />
<code>git fetch origin</code><br />
<code>git reset --hard origin/master</code>
<a name="hints"></a>
<div class="scrollblock block-hints">
<h2>useful hints</h2>
built-in git GUI<br />
<code>gitk</code><br />
use colorful git output<br />
<code>git config color.ui true</code><br />
show log on just one line per commit<br />
<code>git config format.pretty oneline</code><br />
use interactive adding<br />
<code>git add -i</code>
<a name="resources"></a>
<div class="scrollblock block-resources">
<h2>links & resources</h2>
<h3>graphical clients</h3>
<li><a href="">GitX (L) (OSX, open source)</a></li>
<li><a href="">Tower (OSX)</a></li>
<li><a href="">Source Tree (OSX, free)</a></li>
<li><a href="">GitHub for Mac (OSX, free)</a></li>
<li><a href="">Git Community Book</a></li>
<li><a href="">Pro Git</a></li>
<li><a href="">Think like a git</a></li>
<li><a href="">GitHub Help</a></li>
<li><a href="">A Visual Git Guide</a></li>
<a name="comments"></a>
<div class="scrollblock block-comments">
<div id="disqus_thread"></div>
<script type="text/javascript">
var disqus_shortname = 'git-the-simple-guide'; // required: replace example with your forum shortname
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
<noscript>Please enable JavaScript to view the <a href="">comments powered by Disqus.</a></noscript>
<a href="" onClick="recordOutboundLink(this, 'Outbound Links', '');return false;" class="tower"></a>
<a href="files/git_cheat_sheet.pdf" onClick="recordOutboundLink(this, 'Cheat Sheet', 'git-guide');return false;" class="cheatsheet"></a>
Jump to Line
Something went wrong with that request. Please try again.