emacs.d/clones/lisp/stevelosh.com/blog/2013/04/git-koans/index.html

149 lines
7.2 KiB
HTML
Raw Normal View History

2022-10-07 15:47:14 +02:00
<!DOCTYPE html>
<html lang='en'><head><meta charset='utf-8' /><meta name='pinterest' content='nopin' /><link href='../../../../static/css/style.css' rel='stylesheet' type='text/css' /><link href='../../../../static/css/print.css' rel='stylesheet' type='text/css' media='print' /><title>Git Koans / Steve Losh</title></head><body><header><a id='logo' href='https://stevelosh.com/'>Steve Losh</a><nav><a href='../../../index.html'>Blog</a> - <a href='https://stevelosh.com/projects/'>Projects</a> - <a href='https://stevelosh.com/photography/'>Photography</a> - <a href='https://stevelosh.com/links/'>Links</a> - <a href='https://stevelosh.com/rss.xml'>Feed</a></nav></header><hr class='main-separator' /><main id='page-blog-entry'><article><h1><a href='index.html'>Git Koans</a></h1><p class='date'>Posted on April 8th, 2013.</p><p>Inspired by <a href="http://blog.sanctum.geek.nz/vim-koans/">Vim Koans</a>.</p>
<ol class="table-of-contents"><li><a href="index.html#s1-silence">Silence</a></li><li><a href="index.html#s2-one-thing-well">One Thing Well</a></li><li><a href="index.html#s3-only-the-gods">Only the Gods</a></li><li><a href="index.html#s4-the-hobgoblin">The Hobgoblin</a></li><li><a href="index.html#s5-the-long-and-short-of-it">The Long and Short of It</a></li></ol>
<h2 id="s1-silence"><a href="index.html#s1-silence">Silence</a></h2>
<p>A Python programmer handed her <code>~/.gitconfig</code> to Master Git. Among the many
lines were the following:</p>
<pre><code>[alias]
; Explicit is better than implicit. If we want to merge
; we should do so ourselves.
pull = pull --ff-only</code></pre>
<p>Master Git nodded. &quot;<code>git pull origin master</code>,&quot; said the programmer.</p>
<p>Master Git pulled down the latest changes on <code>master</code> and automatically merged
them with the programmer's changes.</p>
<p>&quot;But Master Git, did I not say to only fast-forward in my configuration?!&quot; she
cried.</p>
<p>Master Git looked at her, nodded, and said nothing.</p>
<p>&quot;Then why did you not warn me of a problem with my configuration?&quot; she asked.</p>
<p>Master Git replied: &quot;there was no problem.&quot;</p>
<p>Months later the programmer was reading <code>git --help config</code> for a different
reason and found enlightenment.</p>
<h2 id="s2-one-thing-well"><a href="index.html#s2-one-thing-well">One Thing Well</a></h2>
<p>A UNIX programmer was working in the cubicle farms. As she saw Master Git
traveling down the path, she ran to meet him.</p>
<p>&quot;It is an honor to meet you, Master Git!&quot; she said. &quot;I have been studying the
UNIX way of designing programs that each do one thing well. Surely I can learn
much from you.&quot;</p>
<p>&quot;Surely,&quot; replied Master Git.</p>
<p>&quot;How should I change to a different branch?&quot; asked the programmer.</p>
<p>&quot;Use <code>git checkout</code>.&quot;</p>
<p>&quot;And how should I create a branch?&quot;</p>
<p>&quot;Use <code>git checkout</code>.&quot;</p>
<p>&quot;And how should I update the contents of a single file in my working directory,
without involving branches at all?&quot;</p>
<p>&quot;Use <code>git checkout</code>.&quot;</p>
<p>After this third answer, the programmer was enlightened.</p>
<h2 id="s3-only-the-gods"><a href="index.html#s3-only-the-gods">Only the Gods</a></h2>
<p>The great historian was trying to unravel the intricacies of an incorrect merge
that had happened many months ago. He made a pilgrimage to Master Git to ask
for his help.</p>
<p>&quot;Master Git,&quot; said the historian, &quot;what is the nature of history?&quot;</p>
<p>&quot;History is immutable. To rewrite it later is to tamper with the very fabric of
existence.&quot;</p>
<p>The historian nodded, then asked: &quot;Is that why rebasing commits that have been
pushed is discouraged?&quot;</p>
<p>&quot;Indeed,&quot; said Master Git.</p>
<p>&quot;Splendid!&quot; exclaimed the historian. &quot;I have a historical record of a merge
commit with two parents. How can I find out which branch each parent was
originally made on?&quot;</p>
<p>&quot;History is ephemeral,&quot; replied Master Git, &quot;the knowledge you seek can be
answered only by the gods.&quot;</p>
<p>The historian hung his head as enlightenment crushed down upon him.</p>
<h2 id="s4-the-hobgoblin"><a href="index.html#s4-the-hobgoblin">The Hobgoblin</a></h2>
<p>A novice was learning at the feet of Master Git. At the end of the lesson he
looked through his notes and said, &quot;Master, I have a few questions. May I ask
them?&quot;</p>
<p>Master Git nodded.</p>
<p>&quot;How can I view a list of <em>all</em> tags?&quot;</p>
<p>&quot;<code>git tag</code>&quot;, replied Master Git.</p>
<p>&quot;How can I view a list of <em>all</em> remotes?&quot;</p>
<p>&quot;<code>git remote -v</code>&quot;, replied Master Git.</p>
<p>&quot;How can I view a list of <em>all</em> branches?&quot;</p>
<p>&quot;<code>git branch -a</code>&quot;, replied Master Git.</p>
<p>&quot;And how can I view the current branch?&quot;</p>
<p>&quot;<code>git rev-parse --abbrev-ref HEAD</code>&quot;, replied Master Git.</p>
<p>&quot;How can I delete a remote?&quot;</p>
<p>&quot;<code>git remote rm</code>&quot;, replied Master Git.</p>
<p>&quot;And how can I delete a branch?&quot;</p>
<p>&quot;<code>git branch -d</code>&quot;, replied Master Git.</p>
<p>The novice thought for a few moments, then asked: &quot;Surely some of these could be
made more consistent, so as to be easier to remember in the heat of coding?&quot;</p>
<p>Master Git snapped his fingers. A hobgoblin entered the room and ate the novice
alive. In the afterlife, the novice was enlightened.</p>
<h2 id="s5-the-long-and-short-of-it"><a href="index.html#s5-the-long-and-short-of-it">The Long and Short of It</a></h2>
<p>Master Git and a novice were walking along a bridge.</p>
<p>The novice, wanting to partake of Master Git's vast knowledge, said:
&quot;<code>git branch --help</code>&quot;.</p>
<p>Master Git sat down and lectured her on the seven forms of <code>git branch</code>, and
their many options.</p>
<p>They resumed walking. A few minutes later they encountered an experienced
developer traveling in the opposite direction. He bowed to Master Git and said
&quot;<code>git branch -h</code>&quot;. Master Git tersely informed him of the most common <code>git
branch</code> options. The developer thanked him and continued on his way.</p>
<p>&quot;Master,&quot; said the novice, &quot;what is the nature of long and short options for
commands? I thought they were equivalent, but when that developer used <code>-h</code> you
said something different than when I said <code>--help</code>.&quot;</p>
<p>&quot;Perspective is everything,&quot; answered the Master.</p>
<p>The novice was puzzled. She decided to experiment and said &quot;<code>git -h branch</code>&quot;.</p>
<p>Master Git turned and threw himself off the railing, falling to his death on the
rocks below.</p>
<p>Upon seeing this, the novice was enlightened.</p>
</article></main><hr class='main-separator' /><footer><nav><a href='https://github.com/sjl/'>GitHub</a><a href='https://twitter.com/stevelosh/'>Twitter</a><a href='https://instagram.com/thirtytwobirds/'>Instagram</a><a href='https://hg.stevelosh.com/.plan/'>.plan</a></nav></footer></body></html>