<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Raymond Law &#187; Git</title>
	<atom:link href="http://rayvinly.com/articles/category/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://rayvinly.com</link>
	<description>Badminton on Rails</description>
	<lastBuildDate>Sun, 04 Apr 2010 05:18:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Capistrano Deployment Recipes</title>
		<link>http://rayvinly.com/articles/2008/08/04/capistrano-deployment-recipes/</link>
		<comments>http://rayvinly.com/articles/2008/08/04/capistrano-deployment-recipes/#comments</comments>
		<pubDate>Mon, 04 Aug 2008 16:55:08 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Dealistic]]></category>
		<category><![CDATA[Entrepreneurship]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[capistrano]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[github]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[slicehost]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[Dealistic was first deployed to Slicehost when we were testing it on staging.  However, I only got the 256 slice and low memory is a big problem for Ruby and Mongrel.  We&#8217;ve moved to Amazon EC2 when we launched.  It is running rock solid and we don&#8217;t run out of memory again, [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://dealistic.com/">Dealistic</a> was first deployed to <a href="http://www.slicehost.com/">Slicehost</a> when we were testing it on staging.  However, I only got the 256 slice and low memory is a big problem for Ruby and Mongrel.  We&#8217;ve moved to <a href="http://www.amazon.com/gp/browse.html?node=201590011">Amazon <span class="caps">EC2</span></a> when we launched.  It is running rock solid and we don&#8217;t run out of memory again, at least for now <img src='http://rayvinly.com/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>

<p>As a result of all these, I wrote two <a href="http://www.capify.org/">Capistrano</a> recipes for deployment, for both Slicehost and <span class="caps">EC2. </span> We also use <a href="http://github.com/">GitHub</a> for version control.  I think these deployment recipes may be helpful to others.  So here they are:</p>


<ul>
<li><a href="http://rayvinly.com/wp-content/uploads/2009/02/deploy_slicehost.rb">deploy.rb for Slicehost</a></li>
<li><a href="http://rayvinly.com/wp-content/uploads/2009/02/deploy_ec2.rb">deploy.rb for <span class="caps">EC2</span></a></li>
</ul>



<p>We wrote some custom Capistrano tasks to copy over configuration files, symlink plugins, start/stop <a href="http://backgroundrb.rubyforge.org/">BackgrounDRb</a>, and a custom maintenance page.  But these things are optional.  It should be simple to add/remove things as you see fit.</p><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2008/08/04/capistrano-deployment-recipes/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2008/08/04/capistrano-deployment-recipes/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Tricky Git Submodule</title>
		<link>http://rayvinly.com/articles/2008/04/29/tricky-git-submodule/</link>
		<comments>http://rayvinly.com/articles/2008/04/29/tricky-git-submodule/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 01:15:09 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>
		<category><![CDATA[submodule]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I recently spent a good amount of time figuring out why the acts_as_taggable_on plugin did not work for me.  I used Git&#8217;s submodule to grab the code fom GitHub.


&#62; git submodule add git://github.com/mbleigh/acts-as-taggable-on.git vendor/plugin/acts-as-taggable-on




It seems logical to name my plugin directory with dashes since that&#8217;s what the path suggests, right?  Wrong!  If [...]]]></description>
			<content:encoded><![CDATA[<p>I recently spent a good amount of time figuring out why the <a href="http://www.mbleigh.com/plugins/acts-as-taggable-on-customizable-tagging-for-rails">acts_as_taggable_on</a> plugin did not work for me.  I used Git&#8217;s submodule to grab the code fom GitHub.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git submodule add git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>mbleigh<span style="color: #000000; font-weight: bold;">/</span>acts-as-taggable-on.git vendor<span style="color: #000000; font-weight: bold;">/</span>plugin<span style="color: #000000; font-weight: bold;">/</span>acts-as-taggable-on</pre></div></div>




<p>It seems logical to name my plugin directory with dashes since that&#8217;s what the path suggests, right?  Wrong!  If you do that, it does not work because the plugin expects underscores.  This is probably due to the way Rails finds and loads the plugins, I guess.  Haven&#8217;t had time to really dig deep into that&#8230;</p>

<p>Use this instead:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git submodule add git:<span style="color: #000000; font-weight: bold;">//</span>github.com<span style="color: #000000; font-weight: bold;">/</span>mbleigh<span style="color: #000000; font-weight: bold;">/</span>acts-as-taggable-on.git vendor<span style="color: #000000; font-weight: bold;">/</span>plugin<span style="color: #000000; font-weight: bold;">/</span>acts_as_taggable_on</pre></div></div>




<p>I initially didn&#8217;t pay attention to this because before Git, I just used:</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> script<span style="color: #000000; font-weight: bold;">/</span>plugin <span style="color: #c20cb9; font-weight: bold;">install</span> http:<span style="color: #000000; font-weight: bold;">//</span>svn.intridea.com<span style="color: #000000; font-weight: bold;">/</span>svn<span style="color: #000000; font-weight: bold;">/</span>public<span style="color: #000000; font-weight: bold;">/</span>acts_as_taggable_on<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>




<p>I did not have to explicitly tell where to put the plugin.  script/plugin is a Rails thing while Git is not.</p>

<p>Hopefully anyone who gets tripped up by this in the future will find out this post.</p><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2008/04/29/tricky-git-submodule/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2008/04/29/tricky-git-submodule/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using Git Branches and Stash</title>
		<link>http://rayvinly.com/articles/2008/04/27/using-git-branches-and-stash/</link>
		<comments>http://rayvinly.com/articles/2008/04/27/using-git-branches-and-stash/#comments</comments>
		<pubDate>Sun, 27 Apr 2008 12:48:29 +0000</pubDate>
		<dc:creator>Raymond Law</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Ruby on Rails]]></category>
		<category><![CDATA[Web 2.0]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[I recently started to learn and use Git for one of my projects.  Git encourages easy and cheap branching, here&#8217;s what I do with Git branches and stash to switch between branches while working on different things.

Assume we want to develop yet another blog engine with Rails:

Create the application.  No surprise here!


&#62; rails [...]]]></description>
			<content:encoded><![CDATA[<p>I recently started to learn and use Git for one of my projects.  Git encourages easy and cheap branching, here&#8217;s what I do with Git branches and stash to switch between branches while working on different things.</p>

<p>Assume we want to develop yet another blog engine with Rails:</p>

<p>Create the application.  No surprise here!</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> rails <span style="color: #660033;">-d</span> mysql blog
<span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #7a0874; font-weight: bold;">cd</span> blog</pre></div></div>




<p>Initialize the Git repository.  This will create a .git/ directory in your project.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git init
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> .git<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>




<p>Add everything in your project directory for the next commit to Git.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git add .</pre></div></div>




<p>Lets see what will be commited.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git status
<span style="color: #666666; font-style: italic;"># On branch master</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Initial commit</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Changes to be committed:</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git rm --cached &lt;file&gt;...&quot; to unstage)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#	new file: README</span>
<span style="color: #666666; font-style: italic;">#	new file: Rakefile</span>
<span style="color: #666666; font-style: italic;">#	new file: app/controllers/application.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: app/helpers/application_helper.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: config/boot.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: config/database.yml</span>
<span style="color: #666666; font-style: italic;">#	new file: config/environment.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: config/environments/development.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: config/environments/production.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: config/environments/test.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: config/initializers/inflections.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: config/initializers/mime_types.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: config/routes.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: doc/README_FOR_APP</span>
<span style="color: #666666; font-style: italic;">#	new file: log/development.log</span>
<span style="color: #666666; font-style: italic;">#	new file: log/production.log</span>
<span style="color: #666666; font-style: italic;">#	new file: log/server.log</span>
<span style="color: #666666; font-style: italic;">#	new file: log/test.log</span>
<span style="color: #666666; font-style: italic;">#	new file: public/.htaccess</span>
<span style="color: #666666; font-style: italic;">#	new file: public/404.html</span>
<span style="color: #666666; font-style: italic;">#	new file: public/422.html</span>
<span style="color: #666666; font-style: italic;">#	new file: public/500.html</span>
<span style="color: #666666; font-style: italic;">#	new file: public/dispatch.cgi</span>
<span style="color: #666666; font-style: italic;">#	new file: public/dispatch.fcgi</span>
<span style="color: #666666; font-style: italic;">#	new file: public/dispatch.rb</span>
<span style="color: #666666; font-style: italic;">#	new file: public/favicon.ico</span>
<span style="color: #666666; font-style: italic;">#	new file: public/images/rails.png</span>
<span style="color: #666666; font-style: italic;">#	new file: public/index.html</span>
<span style="color: #666666; font-style: italic;">#	new file: public/javascripts/application.js</span>
<span style="color: #666666; font-style: italic;">#	new file: public/javascripts/controls.js</span>
<span style="color: #666666; font-style: italic;">#	new file: public/javascripts/dragdrop.js</span>
<span style="color: #666666; font-style: italic;">#	new file: public/javascripts/effects.js</span>
<span style="color: #666666; font-style: italic;">#	new file: public/javascripts/prototype.js</span>
<span style="color: #666666; font-style: italic;">#	new file: public/robots.txt</span>
<span style="color: #666666; font-style: italic;">#	new file: script/about</span>
<span style="color: #666666; font-style: italic;">#	new file: script/console</span>
<span style="color: #666666; font-style: italic;">#	new file: script/destroy</span>
<span style="color: #666666; font-style: italic;">#	new file: script/generate</span>
<span style="color: #666666; font-style: italic;">#	new file: script/performance/benchmarker</span>
<span style="color: #666666; font-style: italic;">#	new file: script/performance/profiler</span>
<span style="color: #666666; font-style: italic;">#	new file: script/performance/request</span>
<span style="color: #666666; font-style: italic;">#	new file: script/plugin</span>
<span style="color: #666666; font-style: italic;">#	new file: script/process/inspector</span>
<span style="color: #666666; font-style: italic;">#	new file: script/process/reaper</span>
<span style="color: #666666; font-style: italic;">#	new file: script/process/spawner</span>
<span style="color: #666666; font-style: italic;">#	new file: script/runner</span>
<span style="color: #666666; font-style: italic;">#	new file: script/server</span>
<span style="color: #666666; font-style: italic;">#	new file: test/test_helper.rb</span>
<span style="color: #666666; font-style: italic;">#</span></pre></div></div>




<p>Lets do our first commit.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">'Initial commit'</span>
Created initial commit aa5e7a0: Initial commit
 <span style="color: #000000;">43</span> files changed, <span style="color: #000000;">8362</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> README
 create mode <span style="color: #000000;">100644</span> Rakefile
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>application.rb
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>application_helper.rb
 create mode <span style="color: #000000;">100644</span> config<span style="color: #000000; font-weight: bold;">/</span>boot.rb
 create mode <span style="color: #000000;">100644</span> config<span style="color: #000000; font-weight: bold;">/</span>database.yml
 create mode <span style="color: #000000;">100644</span> config<span style="color: #000000; font-weight: bold;">/</span>environment.rb
 create mode <span style="color: #000000;">100644</span> config<span style="color: #000000; font-weight: bold;">/</span>environments<span style="color: #000000; font-weight: bold;">/</span>development.rb
 create mode <span style="color: #000000;">100644</span> config<span style="color: #000000; font-weight: bold;">/</span>environments<span style="color: #000000; font-weight: bold;">/</span>production.rb
 create mode <span style="color: #000000;">100644</span> config<span style="color: #000000; font-weight: bold;">/</span>environments<span style="color: #000000; font-weight: bold;">/</span>test.rb
 create mode <span style="color: #000000;">100644</span> config<span style="color: #000000; font-weight: bold;">/</span>initializers<span style="color: #000000; font-weight: bold;">/</span>inflections.rb
 create mode <span style="color: #000000;">100644</span> config<span style="color: #000000; font-weight: bold;">/</span>initializers<span style="color: #000000; font-weight: bold;">/</span>mime_types.rb
 create mode <span style="color: #000000;">100644</span> config<span style="color: #000000; font-weight: bold;">/</span>routes.rb
 create mode <span style="color: #000000;">100644</span> doc<span style="color: #000000; font-weight: bold;">/</span>README_FOR_APP
 create mode <span style="color: #000000;">100644</span> log<span style="color: #000000; font-weight: bold;">/</span>development.log
 create mode <span style="color: #000000;">100644</span> log<span style="color: #000000; font-weight: bold;">/</span>production.log
 create mode <span style="color: #000000;">100644</span> log<span style="color: #000000; font-weight: bold;">/</span>server.log
 create mode <span style="color: #000000;">100644</span> log<span style="color: #000000; font-weight: bold;">/</span>test.log
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>.htaccess
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>404.html
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>422.html
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>500.html
 create mode <span style="color: #000000;">100755</span> public<span style="color: #000000; font-weight: bold;">/</span>dispatch.cgi
 create mode <span style="color: #000000;">100755</span> public<span style="color: #000000; font-weight: bold;">/</span>dispatch.fcgi
 create mode <span style="color: #000000;">100755</span> public<span style="color: #000000; font-weight: bold;">/</span>dispatch.rb
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>favicon.ico
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>images<span style="color: #000000; font-weight: bold;">/</span>rails.png
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>index.html
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>application.js
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>controls.js
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>dragdrop.js
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>effects.js
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>javascripts<span style="color: #000000; font-weight: bold;">/</span>prototype.js
 create mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>robots.txt
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>about
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>console
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>destroy
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>generate
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>performance<span style="color: #000000; font-weight: bold;">/</span>benchmarker
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>performance<span style="color: #000000; font-weight: bold;">/</span>profiler
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>performance<span style="color: #000000; font-weight: bold;">/</span>request
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>plugin
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>process<span style="color: #000000; font-weight: bold;">/</span>inspector
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>process<span style="color: #000000; font-weight: bold;">/</span>reaper
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>process<span style="color: #000000; font-weight: bold;">/</span>spawner
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>runner
 create mode <span style="color: #000000;">100755</span> script<span style="color: #000000; font-weight: bold;">/</span>server
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>test_helper.rb</pre></div></div>




<p>Our project is in the Git repository now.  Lets see what branches it currently has.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git branch
<span style="color: #000000; font-weight: bold;">*</span> master</pre></div></div>




<p>It only has one branch called master, which is the default branch created by Gik, a.k.a. Subversion&#8217;s trunk.</p>

<p>Our blog is going to have posts and comments.  So we probably should create the Post and Comment resources.  Before we do that, lets do some forward thinking.  While working on the blog, we likely will be working with posts and comments at the same time.  It will be confusing and unnessarily consume our brain cells if we were to remember which files and changes are for fixing a bug in posts or comments.  It may be a good idea to create separate branches for working on posts and comments.  So lets do that first.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git branch posts
<span style="color: #000000; font-weight: bold;">&gt;</span> git branch comments</pre></div></div>




<p>Use gitk to show a visual picture of where we are.</p>

<p><img src="http://img.skitch.com/20080427-57197wsbi5mrqy76xa53hggid.png" alt="" /></p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git branch
  comments
<span style="color: #000000; font-weight: bold;">*</span> master
  posts</pre></div></div>




<p>So we have three branches: master, posts, and comments.  We are currently working in the master branch.  Great!</p>

<p>Lets switch to the posts branch.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git checkout posts
Switched to branch <span style="color: #ff0000;">&quot;posts&quot;</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> git branch
  comments
  master
<span style="color: #000000; font-weight: bold;">*</span> posts</pre></div></div>




<p>We are now ready to generate our resources</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> script<span style="color: #000000; font-weight: bold;">/</span>generate resource post title:string body:text published:boolean</pre></div></div>




<p>And add and commit these new files to our Git repository.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git add .
<span style="color: #000000; font-weight: bold;">&gt;</span> git commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">'Created Post resource'</span>
Created commit 1ec37dc: Created Post resource
 <span style="color: #000000;">8</span> files changed, <span style="color: #000000;">50</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>posts_controller.rb
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>posts_helper.rb
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>post.rb
 create mode <span style="color: #000000;">100644</span> db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span>001_create_posts.rb
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>posts.yml
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>posts_controller_test.rb
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>post_test.rb</pre></div></div>




<p>If we switch back to our master branch, we find that the Post resource we just created is gone!  Don&#8217;t worry.  They are in the posts branch but not in the master branch.  Gitk shows this.</p>

<p><img src="http://img.skitch.com/20080427-qipj3atwg6r5kee9chj1g69we7.png" alt="" /></p>

<p>Lets switch to the comments branch and create the Comment resource.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git checkout comments
Switched to branch <span style="color: #ff0000;">&quot;comments&quot;</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> script<span style="color: #000000; font-weight: bold;">/</span>generate resource comment name:string blog:string body:text
<span style="color: #000000; font-weight: bold;">&gt;</span> git add .
<span style="color: #000000; font-weight: bold;">&gt;</span> git commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">'Created Comment resource'</span>
Created commit 7f110d3: Created Comment resource
 <span style="color: #000000;">8</span> files changed, <span style="color: #000000;">50</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>comments_controller.rb
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>comments_helper.rb
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>comment.rb
 create mode <span style="color: #000000;">100644</span> db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span>001_create_comments.rb
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>comments.yml
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>comments_controller_test.rb
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>comment_test.rb</pre></div></div>




<p>Now we created a Post resource in the posts branch and a Comment resource in the comments branch.  We want to merge them back together to the master branch.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git checkout master
Switched to branch <span style="color: #ff0000;">&quot;master&quot;</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> git merge posts
Updating c680d0c..1ec37dc
Fast forward
 app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>posts_controller.rb      <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">2</span> ++
 app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>posts_helper.rb              <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">2</span> ++
 app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>post.rb                       <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">2</span> ++
 config<span style="color: #000000; font-weight: bold;">/</span>routes.rb                         <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">2</span> ++
 db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span>001_create_posts.rb           <span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000;">15</span> +++++++++++++++
 test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>posts.yml                  <span style="color: #000000; font-weight: bold;">|</span>   <span style="color: #000000;">11</span> +++++++++++
 test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>posts_controller_test.rb <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">8</span> ++++++++
 test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>post_test.rb                   <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">8</span> ++++++++
 <span style="color: #000000;">8</span> files changed, <span style="color: #000000;">50</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>posts_controller.rb
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>posts_helper.rb
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>post.rb
 create mode <span style="color: #000000;">100644</span> db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span>001_create_posts.rb
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>posts.yml
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>posts_controller_test.rb
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>post_test.rb
<span style="color: #000000; font-weight: bold;">&gt;</span> git merge comments
Auto-merged config<span style="color: #000000; font-weight: bold;">/</span>routes.rb
CONFLICT <span style="color: #7a0874; font-weight: bold;">&#40;</span>content<span style="color: #7a0874; font-weight: bold;">&#41;</span>: Merge conflict <span style="color: #000000; font-weight: bold;">in</span> config<span style="color: #000000; font-weight: bold;">/</span>routes.rb
Automatic merge failed; fix conflicts and <span style="color: #000000; font-weight: bold;">then</span> commit the result.</pre></div></div>




<p>Oops!  There seems to be a config in config/routes.rb.  Lets see what is in that file.</p>


<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#6666ff; font-weight:bold;">ActionController::Routing::Routes</span>.<span style="color:#9900CC;">draw</span> <span style="color:#9966CC; font-weight:bold;">do</span> <span style="color:#006600; font-weight:bold;">|</span>map<span style="color:#006600; font-weight:bold;">|</span>
<span style="color:#006600; font-weight:bold;">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span> HEAD:config<span style="color:#006600; font-weight:bold;">/</span>routes.<span style="color:#9900CC;">rb</span>
  map.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:posts</span>
=======
  map.<span style="color:#9900CC;">resources</span> <span style="color:#ff3333; font-weight:bold;">:comments</span>
<span style="color:#006600; font-weight:bold;">&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span> comments:config<span style="color:#006600; font-weight:bold;">/</span>routes.<span style="color:#9900CC;">rb</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># The priority is based upon order of creation: first created -&gt; highest priority.</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Sample of regular route:</span>
  <span style="color:#008000; font-style:italic;">#   map.connect 'products/:id', :controller =&gt; 'catalog', :action =&gt; 'view'</span>
  <span style="color:#008000; font-style:italic;"># Keep in mind you can assign values other than :controller and :action</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Sample of named route:</span>
  <span style="color:#008000; font-style:italic;">#   map.purchase 'products/:id/purchase', :controller =&gt; 'catalog', :action =&gt; 'purchase'</span>
  <span style="color:#008000; font-style:italic;"># This route can be invoked with purchase_url(:id =&gt; product.id)</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Sample resource route (maps HTTP verbs to controller actions automatically):</span>
  <span style="color:#008000; font-style:italic;">#   map.resources :products</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Sample resource route with options:</span>
  <span style="color:#008000; font-style:italic;">#   map.resources :products, :member =&gt; { :short =&gt; :get, :toggle =&gt; :post }, :collection =&gt; { :sold =&gt; :get }</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Sample resource route with sub-resources:</span>
  <span style="color:#008000; font-style:italic;">#   map.resources :products, :has_many =&gt; [ :comments, :sales ], :has_one =&gt; :seller</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Sample resource route within a namespace:</span>
  <span style="color:#008000; font-style:italic;">#   map.namespace :admin do |admin|</span>
  <span style="color:#008000; font-style:italic;">#     # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)</span>
  <span style="color:#008000; font-style:italic;">#     admin.resources :products</span>
  <span style="color:#008000; font-style:italic;">#   end</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># You can have the root of your site routed with map.root -- just remember to delete public/index.html.</span>
  <span style="color:#008000; font-style:italic;"># map.root :controller =&gt; &quot;welcome&quot;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># See how all your routes lay out with &quot;rake routes&quot;</span>
&nbsp;
  <span style="color:#008000; font-style:italic;"># Install the default routes as the lowest priority.</span>
  map.<span style="color:#9900CC;">connect</span> <span style="color:#996600;">':controller/:action/:id'</span>
  map.<span style="color:#9900CC;">connect</span> <span style="color:#996600;">':controller/:action/:id.:format'</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>Ah, when we generated the resources, they edited the same line on the file.  That&#8217;s an easy fix.  Just get rid of the conflict markers.  Merge again.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git add .
<span style="color: #000000; font-weight: bold;">&gt;</span> git commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">'Merged from comment branch.  Resolved config/routes.rb'</span>
Created commit cfb3b0e: Merged from comment branch.  Resolved config<span style="color: #000000; font-weight: bold;">/</span>routes.rb
 <span style="color: #000000;">8</span> files changed, <span style="color: #000000;">49</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>controllers<span style="color: #000000; font-weight: bold;">/</span>comments_controller.rb
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>helpers<span style="color: #000000; font-weight: bold;">/</span>comments_helper.rb
 create mode <span style="color: #000000;">100644</span> app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>comment.rb
 create mode <span style="color: #000000;">100644</span> db<span style="color: #000000; font-weight: bold;">/</span>migrate<span style="color: #000000; font-weight: bold;">/</span>001_create_comments.rb
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>fixtures<span style="color: #000000; font-weight: bold;">/</span>comments.yml
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>functional<span style="color: #000000; font-weight: bold;">/</span>comments_controller_test.rb
 create mode <span style="color: #000000;">100644</span> test<span style="color: #000000; font-weight: bold;">/</span>unit<span style="color: #000000; font-weight: bold;">/</span>comment_test.rb</pre></div></div>




<p>Now we have both Post and Comment resources in our master branch.  At this point, we can delete the posts and comments branches.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git branch <span style="color: #660033;">-d</span> posts
Deleted branch posts.
<span style="color: #000000; font-weight: bold;">&gt;</span> git branch <span style="color: #660033;">-d</span> comments
error: The branch <span style="color: #ff0000;">'comments'</span> is not an ancestor of your current HEAD.
If you are sure you want to delete it, run <span style="color: #ff0000;">'git branch -D comments'</span>.</pre></div></div>




<p>Since we manually merge and fix the conflict, Git is complaining that it is unsafe to delete the comments branch since we could lose some unmerged changes.  But we know we already have them in the master branch.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git branch <span style="color: #660033;">-D</span> comments
Deleted branch comments.</pre></div></div>




<p>Lets establish some ActiveRecord relationships.  Before we do that, lets create another branch called relationships.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git branch relationships
<span style="color: #000000; font-weight: bold;">&gt;</span> git checkout relationships
Switched to branch <span style="color: #ff0000;">&quot;relationships&quot;</span></pre></div></div>




<p>Add the one-to-many relationship to post.rb.</p>


<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Post <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#5A0A0A; font-weight:bold;">has_many</span> <span style="color:#ff3333; font-weight:bold;">:comments</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>At this point, lets assume our customer notifies us there is an urgent bug in the master branch.  We want to make them happy, so we will temporarily suspend our work in the relationships branch and fix the bug in the master branch, before we come back to finish our work in the relationships branch.</p>

<p>We use a stash to do that.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git stash save
Saved working directory and index state <span style="color: #ff0000;">&quot;WIP on relationships: cfb3b0e... Merged from comment branch.  Resolved config/routes.rb&quot;</span>
HEAD is now at cfb3b0e... Merged from comment branch.  Resolved config<span style="color: #000000; font-weight: bold;">/</span>routes.rb</pre></div></div>




<p>The git-stash man page says:</p>

<blockquote><p>Use git-stash when you want to record the current state of the working directory and the index, but want to go back to a clean working directory.  The command saves your local modifications away and reverts the working directory to match the <span class="caps">HEAD </span>commit.</p></blockquote>

<p>A few more stash commands.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git stash list
stash<span style="color: #000000; font-weight: bold;">@</span><span style="color: #7a0874; font-weight: bold;">&#123;</span><span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#125;</span>: WIP on relationships: cfb3b0e... Merged from comment branch. Resolved config<span style="color: #000000; font-weight: bold;">/</span>routes.rb
<span style="color: #000000; font-weight: bold;">&gt;</span> git stash show
 app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>post.rb <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">1</span> +
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> git stash show <span style="color: #660033;">-p</span>
<span style="color: #c20cb9; font-weight: bold;">diff</span> <span style="color: #660033;">--git</span> a<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>post.rb b<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>post.rb
index 791dcb5..6ad2382 <span style="color: #000000;">100644</span>
<span style="color: #660033;">---</span> a<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>post.rb
+++ b<span style="color: #000000; font-weight: bold;">/</span>app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>post.rb
<span style="color: #000000; font-weight: bold;">@@</span> -<span style="color: #000000;">1</span>,<span style="color: #000000;">2</span> +<span style="color: #000000;">1</span>,<span style="color: #000000;">3</span> <span style="color: #000000; font-weight: bold;">@@</span>
 class Post <span style="color: #000000; font-weight: bold;">&lt;</span> ActiveRecord::Base
+  has_many :comments
 end</pre></div></div>




<p>Our changes are now saved to the stash, as evidenced by running git status.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git status
<span style="color: #666666; font-style: italic;"># On branch relationships</span>
nothing to commit <span style="color: #7a0874; font-weight: bold;">&#40;</span>working directory clean<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>




<p>Lets fix the urgent bug in the master branch.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git checkout master
Switched to branch <span style="color: #ff0000;">&quot;master&quot;</span></pre></div></div>




<p>It turns out the bug is really trivial.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #c20cb9; font-weight: bold;">rm</span> public<span style="color: #000000; font-weight: bold;">/</span>index.html
<span style="color: #000000; font-weight: bold;">&gt;</span> git commit <span style="color: #660033;">-a</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">'Fixed urgent bug'</span>
Created commit 9a6dcf7: Fixed urgent bug
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">0</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">277</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 delete mode <span style="color: #000000;">100644</span> public<span style="color: #000000; font-weight: bold;">/</span>index.html</pre></div></div>




<p>We can resume our work in the relationships branch now.  We need to retrieve the work we have done so far in the branch from the stash.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git checkout relationships
Switched to branch <span style="color: #ff0000;">&quot;relationships&quot;</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> git stash apply
<span style="color: #666666; font-style: italic;"># On branch relationships</span>
<span style="color: #666666; font-style: italic;"># Changed but not updated:</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#	modified:   app/models/post.rb</span>
<span style="color: #666666; font-style: italic;">#</span>
no changes added to commit <span style="color: #7a0874; font-weight: bold;">&#40;</span>use <span style="color: #ff0000;">&quot;git add&quot;</span> and<span style="color: #000000; font-weight: bold;">/</span>or <span style="color: #ff0000;">&quot;git commit -a&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>




<p>Lets finish our relationship modeling by modifying comment.rb</p>


<div class="wp_syntax"><div class="code"><pre class="rails" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> Comment <span style="color:#006600; font-weight:bold;">&lt;</span> <span style="color:#6666ff; font-weight:bold;">ActiveRecord::Base</span>
  <span style="color:#5A0A0A; font-weight:bold;">belongs_to</span> <span style="color:#ff3333; font-weight:bold;">:post</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>




<p>We are ready to commit our changes now.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git commit <span style="color: #660033;">-a</span> <span style="color: #660033;">-m</span> <span style="color: #ff0000;">'Added post-comment relationship'</span>
Created commit f71752b: Added post-comment relationship
 <span style="color: #000000;">2</span> files changed, <span style="color: #000000;">2</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>




<p>A quick peek at gitk.</p>

<p><img src="http://img.skitch.com/20080427-musar19kcq4ftdin6aht12qkaq.png" alt="" /></p>

<p>We can merge the relationships branch to the master branch now.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git checkout master
Switched to branch <span style="color: #ff0000;">&quot;master&quot;</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> git merge relationships
Merge made by recursive.
 app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>comment.rb <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">1</span> +
 app<span style="color: #000000; font-weight: bold;">/</span>models<span style="color: #000000; font-weight: bold;">/</span>post.rb    <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">1</span> +
 <span style="color: #000000;">2</span> files changed, <span style="color: #000000;">2</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">&gt;</span> git branch <span style="color: #660033;">-d</span> relationships
Deleted branch relationships.</pre></div></div>




<p>We can now clear our stash because we already have the changes.</p>


<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&gt;</span> git stash <span style="color: #c20cb9; font-weight: bold;">clear</span></pre></div></div>




<p>Final picture.</p>

<p><img src="http://img.skitch.com/20080427-n7u84ucaks6igsqisk3e6mkmkj.png" alt="" /></p>

<p>Yay!</p><script src="http://feeds.feedburner.com/~s/rayvinly?i=http://rayvinly.com/articles/2008/04/27/using-git-branches-and-stash/" type="text/javascript" charset="utf-8"></script>]]></content:encoded>
			<wfw:commentRss>http://rayvinly.com/articles/2008/04/27/using-git-branches-and-stash/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
