mirror of
https://github.com/RustyRaptor/git-guide.git
synced 2026-12-05 08:25:16 -07:00
161 lines
7.7 KiB
HTML
161 lines
7.7 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<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='http://fonts.googleapis.com/css?family=Chelsea+Market' 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']);
|
|
_gaq.push(['_trackPageview']);
|
|
|
|
(function() {
|
|
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
})();
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<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="https://twitter.com/share" class="twitter-share-button" data-via="rogerdudler">Tweet</a>
|
|
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
|
|
<p class="meta">by <a href="http://www.twitter.com/rogerdudler">Roger Dudler</a> / <a href="http://www.rogerdudler.com">http://www.rogerdudler.com</a></p>
|
|
</div>
|
|
<!-- setup -->
|
|
<a name="setup"></a>
|
|
<div class="scrollblock block-setup">
|
|
<h2>setup</h2>
|
|
<p>
|
|
<a href="http://code.google.com/p/git-osx-installer/downloads/list?can=3">Download git for OSX</a>
|
|
</p>
|
|
<p>
|
|
<a href="http://code.google.com/p/msysgit/downloads/list?can=3">Download git for Windows</a>
|
|
</p>
|
|
</div>
|
|
<a name="create"></a>
|
|
<div class="scrollblock block-create">
|
|
<h2>create a new repository</h2>
|
|
<p>
|
|
create a new directory, open it and perform a <br />
|
|
<code>git init</code><br />
|
|
to create a new git repository.
|
|
</p>
|
|
</div>
|
|
<a name="checkout"></a>
|
|
<div class="scrollblock block-checkout">
|
|
<h2>checkout a repository</h2>
|
|
<p>
|
|
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>
|
|
</p>
|
|
</div>
|
|
<a name="trees"></a>
|
|
<div class="scrollblock block-trees">
|
|
<h2>trees</h2>
|
|
<p>
|
|
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.
|
|
</p>
|
|
</div>
|
|
<a name="add"></a>
|
|
<div class="scrollblock block-add">
|
|
<h2>add & commit</h2>
|
|
<p>
|
|
You can propose changes (add it to the <b>Index</b>) using<br />
|
|
<code>git add <filename></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.
|
|
</p>
|
|
</div>
|
|
<a name="push"></a>
|
|
<div class="scrollblock block-remote">
|
|
<h2>pushing changes</h2>
|
|
<p>
|
|
Your changes are now in the <b>HEAD</b> of your local working copy. To send those changes to your remote repository, you need to perform a<br />
|
|
<code>git push origin master</code><br />
|
|
Change <i>master</i> to whatever branch you want to push your changes to.
|
|
</p>
|
|
</div>
|
|
<a name="branching"></a>
|
|
<div class="scrollblock block-branching">
|
|
<h2>branching</h2>
|
|
<p>
|
|
Branches are used to develop features isolated from the <i>master</i> branch. You should <b>never</b> commit directly to the <i>master</i> branch. Use other branches and merge them back to the master branch. So, the master branch will be kept clean.
|
|
</p>
|
|
<p>
|
|
create a new branch named "feature_x" using<br />
|
|
<code>git checkout -b feature_x</code><br />
|
|
rename it to "abc" using<br />
|
|
<code>git branch -m feature_x abc</code><br />
|
|
or delete it<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 <branch></code>
|
|
</p>
|
|
</div>
|
|
<a name="update"></a>
|
|
<div class="scrollblock block-merging">
|
|
<h2>update & merge</h2>
|
|
<p>
|
|
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 <branch></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 <filename></code><br />
|
|
before merging changes, you can also preview them by using<br />
|
|
<code>git diff <source_branch> <target_branch></code>
|
|
</p>
|
|
</div>
|
|
<a name="tagging"></a>
|
|
<div class="scrollblock block-tagging">
|
|
<h2>tagging</h2>
|
|
<p>
|
|
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>
|
|
</p>
|
|
</div>
|
|
<a name="revert"></a>
|
|
<div class="scrollblock block-revert">
|
|
<h2>reverting changes</h2>
|
|
<p>
|
|
In case you did something wrong (which for sure never happens ;) you can revert changes using the command<br />
|
|
<code>git reset --hard HEAD</code><br />
|
|
this reverts your local repository (working dir, index and HEAD) to the last committed version. if you want to keep your working version, drop <i>--hard</i>.
|
|
</p>
|
|
<p>
|
|
To revert your changes to the latest remote version you need to use these two commands<br />
|
|
<code>git fetch origin</code><br />
|
|
<code>git reset --hard origin/master</code>
|
|
</p>
|
|
</div>
|
|
<a name="hints"></a>
|
|
<div class="scrollblock block-hints">
|
|
<h2>useful hints</h2>
|
|
<p>
|
|
use colorful git output<br />
|
|
<code>git config color.ui</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>
|
|
</p>
|
|
</div>
|
|
</body>
|
|
</html> |