149 lines
7.2 KiB
HTML
149 lines
7.2 KiB
HTML
|
<!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. "<code>git pull origin master</code>," 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>"But Master Git, did I not say to only fast-forward in my configuration?!" she
|
||
|
cried.</p>
|
||
|
|
||
|
<p>Master Git looked at her, nodded, and said nothing.</p>
|
||
|
|
||
|
<p>"Then why did you not warn me of a problem with my configuration?" she asked.</p>
|
||
|
|
||
|
<p>Master Git replied: "there was no problem."</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>"It is an honor to meet you, Master Git!" she said. "I have been studying the
|
||
|
UNIX way of designing programs that each do one thing well. Surely I can learn
|
||
|
much from you."</p>
|
||
|
|
||
|
<p>"Surely," replied Master Git.</p>
|
||
|
|
||
|
<p>"How should I change to a different branch?" asked the programmer.</p>
|
||
|
|
||
|
<p>"Use <code>git checkout</code>."</p>
|
||
|
|
||
|
<p>"And how should I create a branch?"</p>
|
||
|
|
||
|
<p>"Use <code>git checkout</code>."</p>
|
||
|
|
||
|
<p>"And how should I update the contents of a single file in my working directory,
|
||
|
without involving branches at all?"</p>
|
||
|
|
||
|
<p>"Use <code>git checkout</code>."</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>"Master Git," said the historian, "what is the nature of history?"</p>
|
||
|
|
||
|
<p>"History is immutable. To rewrite it later is to tamper with the very fabric of
|
||
|
existence."</p>
|
||
|
|
||
|
<p>The historian nodded, then asked: "Is that why rebasing commits that have been
|
||
|
pushed is discouraged?"</p>
|
||
|
|
||
|
<p>"Indeed," said Master Git.</p>
|
||
|
|
||
|
<p>"Splendid!" exclaimed the historian. "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?"</p>
|
||
|
|
||
|
<p>"History is ephemeral," replied Master Git, "the knowledge you seek can be
|
||
|
answered only by the gods."</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, "Master, I have a few questions. May I ask
|
||
|
them?"</p>
|
||
|
|
||
|
<p>Master Git nodded.</p>
|
||
|
|
||
|
<p>"How can I view a list of <em>all</em> tags?"</p>
|
||
|
|
||
|
<p>"<code>git tag</code>", replied Master Git.</p>
|
||
|
|
||
|
<p>"How can I view a list of <em>all</em> remotes?"</p>
|
||
|
|
||
|
<p>"<code>git remote -v</code>", replied Master Git.</p>
|
||
|
|
||
|
<p>"How can I view a list of <em>all</em> branches?"</p>
|
||
|
|
||
|
<p>"<code>git branch -a</code>", replied Master Git.</p>
|
||
|
|
||
|
<p>"And how can I view the current branch?"</p>
|
||
|
|
||
|
<p>"<code>git rev-parse --abbrev-ref HEAD</code>", replied Master Git.</p>
|
||
|
|
||
|
<p>"How can I delete a remote?"</p>
|
||
|
|
||
|
<p>"<code>git remote rm</code>", replied Master Git.</p>
|
||
|
|
||
|
<p>"And how can I delete a branch?"</p>
|
||
|
|
||
|
<p>"<code>git branch -d</code>", replied Master Git.</p>
|
||
|
|
||
|
<p>The novice thought for a few moments, then asked: "Surely some of these could be
|
||
|
made more consistent, so as to be easier to remember in the heat of coding?"</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:
|
||
|
"<code>git branch --help</code>".</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
|
||
|
"<code>git branch -h</code>". 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>"Master," said the novice, "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>."</p>
|
||
|
|
||
|
<p>"Perspective is everything," answered the Master.</p>
|
||
|
|
||
|
<p>The novice was puzzled. She decided to experiment and said "<code>git -h branch</code>".</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>
|