-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
381 lines (246 loc) · 20.7 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
<!DOCTYPE html>
<!--[if IEMobile 7 ]><html class="no-js iem7"><![endif]-->
<!--[if lt IE 9]><html class="no-js lte-ie8"><![endif]-->
<!--[if (gt IE 8)|(gt IEMobile 7)|!(IEMobile)|!(IE)]><!--><html class="no-js" lang="en"><!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Git Tutorials Suck, A Sucky Git Tutorial - Garbled</title>
<meta name="author" content="Ben Hamill">
<meta name="description" content="Context… Perhaps Too Much Of It So I was reading this blog post about learning and explaining because Carl Youngblood tweeted about it. I think …">
<!-- http://t.co/dKP3o1e -->
<meta name="HandheldFriendly" content="True">
<meta name="MobileOptimized" content="320">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="canonical" href="http://garbled.benhamill.com/2009/03/18/git-tutorials-suck-a-sucky-git-tutorial">
<link href="/favicon.png" rel="icon">
<link href="/stylesheets/screen.css" media="screen, projection" rel="stylesheet" type="text/css">
<link href="/atom.xml" rel="alternate" title="Garbled" type="application/atom+xml">
<script src="/javascripts/modernizr-2.0.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>!window.jQuery && document.write(unescape('%3Cscript src="./javascripts/lib/jquery.min.js"%3E%3C/script%3E'))</script>
<script src="/javascripts/octopress.js" type="text/javascript"></script>
<!--Fonts from Google"s Web font directory at http://google.com/webfonts -->
<link href="http://fonts.googleapis.com/css?family=PT+Serif:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
<link href="http://fonts.googleapis.com/css?family=PT+Sans:regular,italic,bold,bolditalic" rel="stylesheet" type="text/css">
</head>
<body >
<header role="banner"><hgroup>
<h1><a href="/">Garbled</a></h1>
</hgroup>
</header>
<nav role="navigation"><div>
<ul class="subscription" data-subscription="rss">
<li><a href="/atom.xml" rel="subscribe-rss" title="subscribe via RSS">RSS</a></li>
</ul>
<form action="http://google.com/search" method="get">
<fieldset role="search">
<input type="hidden" name="q" value="site:garbled.benhamill.com" />
<input class="search" type="text" name="q" results="0" placeholder="Search"/>
</fieldset>
</form>
<ul class="main-navigation">
<li><a href="/">Blog</a></li>
<li><a href="/blog/archives">Archives</a></li>
<li><a href="/about">About</a></li>
</ul>
<div>
</nav>
<div id="main-wrapper">
<div id="main">
<div id="content">
<div>
<article class="hentry" role="article">
<header>
<h1 class="entry-title">Git Tutorials Suck, a Sucky Git Tutorial</h1>
<p class="meta">
<time datetime="2009-03-18T00:00:00-05:00" pubdate data-updated="true">Mar 18<span>th</span>, 2009</time>
</p>
</header>
<div class="entry-content"><h2>Context… Perhaps Too Much Of It</h2>
<p>So I was reading <a href="http://byorgey.wordpress.com/2009/01/12/abstraction-intuition-and-the-monad-tutorial-fallacy/">this blog post</a> about learning and explaining because Carl Youngblood <a href="http://twitter.com/carl_youngblood/status/1115967090">tweeted about it</a>. I think Carl's right: I had a hard time learning git (by which I don't mean to imply I'm some sort of expert now, but the learning is going easier now).</p>
<p>I think the main problem that I had was this: Having learned Subversion, with it's central repository, it was a hard abstract thing to understand. And some (I feel many of the ones I read, anyway) of the tutorials out there try to start at the abstract. Little help that did me (see above-linked article. Really, it's very good). And even ignoring those, I had to read a lot lot <em>lot</em> of the practical ones before things started sinking in.</p>
<p>So I've sort of come to understand that, actually, the tutorials don't suck; learning abstract things just takes time and, at the time, that can be frustrating. So I'm going to offer my own little sucky tutorial, which will focus on the practical aspects and, if you read this and don't get it, you can follow some links at the end to other articles I found helpful and maybe, after roughly a week, you'll have your 'ah-Ha!' moment and think about how git is just like monads… whatever the heck those are.</p>
<p>A lot of tutorials for git newbies start out explaining the Staging Area with some kind of metaphor so that it seems friendly or, I suspect, out of some subconscious wish to actually obscure it from Subversion converts so that git seems more familiar–more like SVN, which it is not very much like at all. I'm not going to really talk about it much. When we get to the commands that affect it (shortly, here), I'll explain what they do. You can make the abstraction your self.</p>
<p>I'm intentionally writing this off the top of my head for two reasons: If I have to look up a command, then you might as well read whatever tutorial I looked it up on and if I have to look it up, then I clearly don't use it all the time and thus, you don't need to know it to get going on Git.</p>
<h2>The Tutorial</h2>
<p>I've got six sections to this thing with (I hope) at least vaguely descriptive names. They are:
<ol>
<li>Setup</li>
<li>Initial Commit</li>
<li>SitRep</li>
<li> Staging Area</li>
<li> Remote Repo</li>
<li>Conclusion/Links</li>
</ol></p>
<h3>Setup</h3>
<p>You have a project you just started in a directory called 'notes'. This isn't even code, it's just notes about something that you want to version control and back up. It's a collection of text files and the directory structure is something like this.</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ pwd
</span><span class='line'>~/notes/
</span><span class='line'>$ ls
</span><span class='line'>contact_info.txt general.txt outline.txt</span></code></pre></td></tr></table></div></figure>
<p>After <a href="http://git-scm.com/download/">installing git</a> as appropriate for your operating system, you start out by typing in the command line <code>git init</code>. This will create a directory called <code>.git</code> in <code>notes/</code>. There's some stuff in there, but for the most part, you can ignore this for now. Suffice to say it's where git does it's book-keeping. What you've got now is a local git repository or, as the kids say, a "local repo", but nothing's in it.</p>
<h3>Initial Commit</h3>
<p>So you do a <code>git add .</code> (note the trailing period). This will toss everything (that's what the period means) in <code>notes/</code> into the staging area (including stuff that's in directories that're in directories that're in <code>notes/</code> etc.). The repo is still empty. To actual save stuff once it's been staged, you do like this:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ git commit -m 'Initial commit.'
</span><span class='line'>[master (root-commit)]: created 7db8343: "Initial commit."
</span><span class='line'>0 files changed, 0 insertions(+), 0 deletions(-)
</span><span class='line'>create mode 100644 contact_info.txt
</span><span class='line'>create mode 100644 general.txt
</span><span class='line'>create mode 100644 outline.txt</span></code></pre></td></tr></table></div></figure>
<p>The <code>-m</code> option says you're going to specify your commit message right after. Sometimes, you'll want to leave a longer message, in which case, you forget the <code>-m</code> and git will automatically fire up a default text editor where you can put in longer stuff. Since a lot of that varies widely from OS to OS, I'm going to skip it and you can read more details on other tutorials (see below). Notice that you get a list of what's changed (you created 3 new files in the repo) and you get your comment back in the output. Splendid.</p>
<h3>SitRep</h3>
<p>Now you've made your initial commit, and your stuff is in version control. Go into <code>contact_info.txt</code> and add something (doesn't matter what for these purposes). Imagine you've made that change and then walked away and forgotten about it. You can use <code>git status</code> to see what's new, thusly:</p>
<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ git status
</span><span class='line'># On branch master
</span><span class='line'># Changed but not updated:
</span><span class='line'># (use "git add <file>..." to update what will be committed)
</span><span class='line'># (use "git checkout -- <file>..." to discard changes in working directory)
</span><span class='line'>#
</span><span class='line'># modified: contact_info.txt
</span><span class='line'>#
</span><span class='line'>no changes added to commit (use "git add" and/or "git commit -a")</span></code></pre></td></tr></table></div></figure>
<p>Using <code>git status</code> is just like a reminder. It doesn't tell you much, but it can jog your memory about what you've already staged or what you changed and didn't stage or what files you added. To get the real scoop about how a file changed, you use <code>git diff</code>. When you run <code>git diff contact_info.txt</code> the output will vary depending on what you had initially and what you added, but the gist is this: It will show you the changes (all of them) with a + before the line for additions and a - before the line for deletions. Generally, it gives a few lines before and after a change for context.</p>
<p>So let's add our new <code>contact_info</code> change to the staging area and commit it, yeah? Do <code>git add contact_info.txt</code> and then <code>git commit -m 'Updated contact info'</code> or similar. Whatever comment you write is fine. Note we could've used <code>git add .</code> but I wanted to show the single-file syntax.</p>
<h3>Staging Area</h3>
<p>Now let's put in some stuff into the <code>outline.txt</code>. Whatever you want. Just some stuff. Save it. But wait! We should also add some stuff to the general notes, just a quick overview at least, so put some stuff in there. We'll finish the outline changes in a second. This is so much more pressing. Obviously.</p>
<p>Now, it's good repo etiquette to only commit stuff atomically, which is to say that all the changes have to do with each other. Some people will say that you should only commit stuff that works (code compiles or whatever), but with git that's less of a concern. I'll come back to this point. What I'm getting at now is that you started one change and realized another needed to be made before you finished the first one. Now you want to commit only the second one, right? Simple: <code>git add general.txt</code> then <code>git commit -m 'Added overview'</code>. Because you never staged the outline (with your half-way-made changes), it doesn't get committed. Later, if you need to revert that commit or whatever, you won't have to worry that something else is mixed in there. Now, go ahead and finish your outline changes, and commit them. You should be able to do it on your own now.</p>
<h3>Remote Repo</h3>
<p>So, then… we're version controlling this stuff. What if you want to get at it from another computer or let someone else get at it or… something? Pop on over to <a href="http://github.com/">Git Hub</a> which is my remote repo host of choice. There are others. Shop around, if you like. After you create an account, you can <a href="https://github.com/repositories/new">create a new remote repo</a> called whatever you want. You'll then be shown a page with some directions. Follow the ones under the heading "Existing Git Repo?"</p>
<p>The <code>git remote add origin git@github.com:<username>/<project>.git</code> command basically tells git where your remote repo is. You can have more than one if you like and, actually, do all sorts of crazy things with naming if you like, but I just want to handle the default, assumed case with this tutorial. One interesting thing: Github gives you two addresses for each repository (other hosts may do the same, I don't know). The one that starts <code>git@github.com</code> is your read/write address and there's one that starts <code>git://github.com</code> which is your read-only address. Since this is your own repo, you want to make sure to use the read/write address.</p>
<p>The <code>git push origin master</code> command is what actually moves your commits to the remote repo. <em>This</em> is where I recommend you adhere to the "only stuff that works" doctrine. If this is code, and you're sharing the repo with your team or whatever, this is where they can get at it, so you don't want to hand them broken stuff or half-finished ideas or whatever. So only <strong>push</strong> code that compiles/works. Pushing your code updates the remote repo with all the commits you've made since your last push.</p>
<p>The way you (or someone else) gets commits out of a repo is by using <code>git pull</code>. It takes the same arguments as <code>git push</code>. It will pull the commits down and then try to reconcile those changes with any that you've made since the last time your local repo was in the same state as the remote repo.</p>
<h3>Conclusion/Links</h3>
<p>I feel like this has gotten pretty long and I don't want to put too much information all at once. That should be enough to get you started and, really, just try it out for a while and get comfortable with the basics. Don't be afraid, if you get something out of whack and realize you've done something wrong, to kill your .git directory (which will delete the local repo) and start again from the top. I've intentionally left a lot of stuff out (like push/pull and branches and multiple remote repos can get kind of hairy), so here's some documentation, blog posts and articles that I've found helpful. These are in no particular order and some are more advanced than others, so just start clicking and see what you like:</p>
<ul>
<li><a href="http://github.com/guides/home">Github’s Guides page</a></li>
<li><a href="http://git-scm.com/">The Git Homepage</a></li>
<li><a href="http://www-cs-students.stanford.edu/~blynn/gitmagic/">Git Magic</a> (a huge work)</li>
<li>Using Git Without Feeling Stupid <a href="http://smalltalk.gnu.org/blog/bonzinip/using-git-without-feeling-stupid-part-1">part 1</a> and <a href="http://smalltalk.gnu.org/blog/bonzinip/using-git-without-feeling-stupid-part-2">part 2</a></li>
<li><a href="http://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide">Awesome StackOverflow page</a></li>
<li><a href="http://cheat.errtheblog.com/s/git">$ cheat git</a></li>
<li><a href="http://www.eecs.harvard.edu/~cduan/technical/git/">Understanding Git Conceptually</a></li>
<li><a href="http://eagain.net/articles/git-for-computer-scientists/">Git for Computer Scientists</a> (highly technical and abstract)</li>
<li><a href="http://whygitisbetterthanx.com/">Why Git is Better Than X</a> (Not only evangelical, but some helpful stuff)</li>
<li><a href="http://learn.github.com/">Github’s Learn page</a></li>
</ul>
<p>If you want to ask me about git or whatever, feel free to email me or leave something in the comments. Also, if you spot a mistake or something here doesn't make sense, <em>please</em> let me know. Hope this is helpful to someone.</p>
</div>
<footer>
<p class="meta">
<span class="byline author vcard">Posted by <span class="fn">Ben Hamill</span></span>
<time datetime="2009-03-18T00:00:00-05:00" pubdate data-updated="true">Mar 18<span>th</span>, 2009</time>
</p>
<p class="no-comments meta">
There's not a comments section on this blog any more. If you<br>
want, tweet at me or write your own post and send me the link.
</p>
<div class="sharing">
<a href="http://twitter.com/share" class="twitter-share-button" data-url="http://garbled.benhamill.com/2009/03/18/git-tutorials-suck-a-sucky-git-tutorial/" data-via="benhamill" data-counturl="http://garbled.benhamill.com/2009/03/18/git-tutorials-suck-a-sucky-git-tutorial/" >Tweet</a>
</div>
<p class="meta">
<a class="basic-alignment left" href="/2009/02/12/version-control-your-computer/" title="Previous Post: Version Control Your Computer">« Version Control Your Computer</a>
<a class="basic-alignment right" href="/2009/04/30/bad-getting-away-with-it/" title="Next Post: Bad & Getting Away With It">Bad & Getting Away With It »</a>
</p>
</footer>
</article>
</div>
<aside class="sidebar">
<section>
<h1>About Me</h1>
<div id="twitter-profile">
<div id="author-card">
<img src="http://www.gravatar.com/avatar/4938b4569f1366168b705ce9c774ea5e" alt="Gravatar of Ben Hamill " title="Gravatar of Ben Hamill" />
<p id="name">Ben Hamill</p>
<p id="handle">@<a href="http://twitter.com/benhamill">benhamill</a></p>
<p id="liame">
<span id="obf"><script>document.getElementById("obf").innerHTML="<n uers=\"znvygb:ora@oraunzvyy.pbz\" gnetrg=\"_oynax\">ora@oraunzvyy.pbz</n>".replace(/[a-zA-Z]/g,function(c){return String.fromCharCode((c<="Z"?90:122)>=(c=c.charCodeAt(0)+13)?c:c-26);});</script>
<noscript><span style="unicode-bidi:bidi-override;direction:rtl;">moc.llimahneb@neb</span></noscript></span>
</p>
</div>
<p>Rubyist, hacker, gamer (video, board, role-playing), fanboy (Linux, git, vim, Firefly, Dr Pepper), language pedant. Nerd.</p>
</div>
</section>
<section>
<h1>Recent Posts</h1>
<ul id="recent_posts">
<li class="post">
<a href="/2013/11/12/hal-client-update-cetacean/">HAL Client Update: Cetacean</a>
</li>
<li class="post">
<a href="/2013/11/05/thinking-about-hal-clients/">Thinking About HAL Clients</a>
</li>
<li class="post">
<a href="/2013/09/18/bens-gem-maintainer-handbook/">Ben's Gem Maintainer Handbook</a>
</li>
<li class="post">
<a href="/2013/09/03/never-type-bundle-exec-again/">Never Type bundle exec Again</a>
</li>
<li class="post">
<a href="/2013/04/28/social-justice-is-made-of-empathy/">Social Justice is Made of Empathy</a>
</li>
</ul>
</section>
<section>
<h1>GitHub Repos</h1>
<ul id="gh_repos">
<li class="loading">Status updating...</li>
</ul>
<a href="https://github.com/benhamill">@benhamill</a> on GitHub
<script type="text/javascript">
$(document).ready(function(){
if (!window.jXHR){
var jxhr = document.createElement('script');
jxhr.type = 'text/javascript';
jxhr.src = '/javascripts/libs/jXHR.js';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(jxhr, s);
}
github.showRepos({
user: 'benhamill',
count: 5,
skip_forks: true,
target: '#gh_repos'
});
});
</script>
<script src="/javascripts/github.js" type="text/javascript"> </script>
</section>
</aside>
</div>
</div>
</div>
<footer role="contentinfo"><p>
Copyright © 2013 - Ben Hamill -
<span class="credit">Powered by <a href="http://octopress.org">Octopress</a></span>
</p>
</footer>
<script type="text/javascript">
(function(){
var twitterWidgets = document.createElement('script');
twitterWidgets.type = 'text/javascript';
twitterWidgets.async = true;
twitterWidgets.src = 'http://platform.twitter.com/widgets.js';
document.getElementsByTagName('head')[0].appendChild(twitterWidgets);
})();
</script>
</body>
</html>