<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Raymond Law: Using Git Branches and Stash</title>
    <link>http://blog.rayvinly.com/articles/2008/04/27/using-git-branches-and-stash</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description></description>
    <item>
      <title>Using Git Branches and Stash</title>
      <description>&lt;p&gt;I recently started to learn and use Git for one of my projects.  Git encourages easy and cheap branching, here&amp;#8217;s what I do with Git branches and stash to switch between branches while working on different things.&lt;/p&gt;


	&lt;p&gt;Assume we want to develop yet another blog engine with Rails:&lt;/p&gt;


	&lt;p&gt;Create the application.  No surprise here!&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; rails -d mysql blog
&amp;gt; cd blog&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Initialize the Git repository.  This will create a .git/ directory in your project.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git init
Initialized empty Git repository in .git/&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Add everything in your project directory for the next commit to Git.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git add .&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Lets see what will be commited.&lt;/p&gt;


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

	&lt;p&gt;Lets do our first commit.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git commit -m 'Initial commit'
Created initial commit aa5e7a0: Initial commit
 43 files changed, 8362 insertions(+), 0 deletions(-)
 create mode 100644 README
 create mode 100644 Rakefile
 create mode 100644 app/controllers/application.rb
 create mode 100644 app/helpers/application_helper.rb
 create mode 100644 config/boot.rb
 create mode 100644 config/database.yml
 create mode 100644 config/environment.rb
 create mode 100644 config/environments/development.rb
 create mode 100644 config/environments/production.rb
 create mode 100644 config/environments/test.rb
 create mode 100644 config/initializers/inflections.rb
 create mode 100644 config/initializers/mime_types.rb
 create mode 100644 config/routes.rb
 create mode 100644 doc/README_FOR_APP
 create mode 100644 log/development.log
 create mode 100644 log/production.log
 create mode 100644 log/server.log
 create mode 100644 log/test.log
 create mode 100644 public/.htaccess
 create mode 100644 public/404.html
 create mode 100644 public/422.html
 create mode 100644 public/500.html
 create mode 100755 public/dispatch.cgi
 create mode 100755 public/dispatch.fcgi
 create mode 100755 public/dispatch.rb
 create mode 100644 public/favicon.ico
 create mode 100644 public/images/rails.png
 create mode 100644 public/index.html
 create mode 100644 public/javascripts/application.js
 create mode 100644 public/javascripts/controls.js
 create mode 100644 public/javascripts/dragdrop.js
 create mode 100644 public/javascripts/effects.js
 create mode 100644 public/javascripts/prototype.js
 create mode 100644 public/robots.txt
 create mode 100755 script/about
 create mode 100755 script/console
 create mode 100755 script/destroy
 create mode 100755 script/generate
 create mode 100755 script/performance/benchmarker
 create mode 100755 script/performance/profiler
 create mode 100755 script/performance/request
 create mode 100755 script/plugin
 create mode 100755 script/process/inspector
 create mode 100755 script/process/reaper
 create mode 100755 script/process/spawner
 create mode 100755 script/runner
 create mode 100755 script/server
 create mode 100644 test/test_helper.rb&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Our project is in the Git repository now.  Lets see what branches it currently has.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git branch
* master&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

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


	&lt;p&gt;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.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git branch posts
&amp;gt; git branch comments&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Use gitk to show a visual picture of where we are.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://img.skitch.com/20080427-57197wsbi5mrqy76xa53hggid.png" alt="" /&gt;&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git branch
  comments
* master
  posts&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;So we have three branches: master, posts, and comments.  We are currently working in the master branch.  Great!&lt;/p&gt;


	&lt;p&gt;Lets switch to the posts branch.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git checkout posts
Switched to branch &amp;quot;posts&amp;quot;
&amp;gt; git branch
  comments
  master
* posts&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;We are now ready to generate our resources&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; script/generate resource post title:string body:text published:boolean&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;And add and commit these new files to our Git repository.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git add .
&amp;gt; git commit -m 'Created Post resource'
Created commit 1ec37dc: Created Post resource
 8 files changed, 50 insertions(+), 0 deletions(-)
 create mode 100644 app/controllers/posts_controller.rb
 create mode 100644 app/helpers/posts_helper.rb
 create mode 100644 app/models/post.rb
 create mode 100644 db/migrate/001_create_posts.rb
 create mode 100644 test/fixtures/posts.yml
 create mode 100644 test/functional/posts_controller_test.rb
 create mode 100644 test/unit/post_test.rb&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

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


	&lt;p&gt;&lt;img src="http://img.skitch.com/20080427-qipj3atwg6r5kee9chj1g69we7.png" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;Lets switch to the comments branch and create the Comment resource.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git checkout comments
Switched to branch &amp;quot;comments&amp;quot;
&amp;gt; script/generate resource comment name:string blog:string body:text
&amp;gt; git add .
&amp;gt; git commit -m 'Created Comment resource'
Created commit 7f110d3: Created Comment resource
 8 files changed, 50 insertions(+), 0 deletions(-)
 create mode 100644 app/controllers/comments_controller.rb
 create mode 100644 app/helpers/comments_helper.rb
 create mode 100644 app/models/comment.rb
 create mode 100644 db/migrate/001_create_comments.rb
 create mode 100644 test/fixtures/comments.yml
 create mode 100644 test/functional/comments_controller_test.rb
 create mode 100644 test/unit/comment_test.rb&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;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.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git checkout master
Switched to branch &amp;quot;master&amp;quot;
&amp;gt; git merge posts
Updating c680d0c..1ec37dc
Fast forward
 app/controllers/posts_controller.rb      |    2 ++
 app/helpers/posts_helper.rb              |    2 ++
 app/models/post.rb                       |    2 ++
 config/routes.rb                         |    2 ++
 db/migrate/001_create_posts.rb           |   15 +++++++++++++++
 test/fixtures/posts.yml                  |   11 +++++++++++
 test/functional/posts_controller_test.rb |    8 ++++++++
 test/unit/post_test.rb                   |    8 ++++++++
 8 files changed, 50 insertions(+), 0 deletions(-)
 create mode 100644 app/controllers/posts_controller.rb
 create mode 100644 app/helpers/posts_helper.rb
 create mode 100644 app/models/post.rb
 create mode 100644 db/migrate/001_create_posts.rb
 create mode 100644 test/fixtures/posts.yml
 create mode 100644 test/functional/posts_controller_test.rb
 create mode 100644 test/unit/post_test.rb
&amp;gt; git merge comments
Auto-merged config/routes.rb
CONFLICT (content): Merge conflict in config/routes.rb
Automatic merge failed; fix conflicts and then commit the result.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Oops!  There seems to be a config in config/routes.rb.  Lets see what is in that file.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="constant"&gt;ActionController&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Routing&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Routes&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;draw&lt;/span&gt; &lt;span class="keyword"&gt;do&lt;/span&gt; &lt;span class="punct"&gt;|&lt;/span&gt;&lt;span class="ident"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;|&lt;/span&gt;
&lt;span class="punct"&gt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;HEAD&lt;/span&gt;&lt;span class="symbol"&gt;:config&lt;/span&gt;&lt;span class="punct"&gt;/&lt;/span&gt;&lt;span class="ident"&gt;routes&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;rb&lt;/span&gt;
  &lt;span class="ident"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;resources&lt;/span&gt; &lt;span class="symbol"&gt;:posts&lt;/span&gt;
&lt;span class="punct"&gt;=======&lt;/span&gt;
  &lt;span class="ident"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;resources&lt;/span&gt; &lt;span class="symbol"&gt;:comments&lt;/span&gt;
&lt;span class="punct"&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class="ident"&gt;comments&lt;/span&gt;&lt;span class="symbol"&gt;:config&lt;/span&gt;&lt;span class="punct"&gt;/&lt;/span&gt;&lt;span class="ident"&gt;routes&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;rb&lt;/span&gt;

  &lt;span class="comment"&gt;# The priority is based upon order of creation: first created -&amp;gt; highest priority.&lt;/span&gt;

  &lt;span class="comment"&gt;# Sample of regular route:&lt;/span&gt;
  &lt;span class="comment"&gt;#   map.connect 'products/:id', :controller =&amp;gt; 'catalog', :action =&amp;gt; 'view'&lt;/span&gt;
  &lt;span class="comment"&gt;# Keep in mind you can assign values other than :controller and :action&lt;/span&gt;

  &lt;span class="comment"&gt;# Sample of named route:&lt;/span&gt;
  &lt;span class="comment"&gt;#   map.purchase 'products/:id/purchase', :controller =&amp;gt; 'catalog', :action =&amp;gt; 'purchase'&lt;/span&gt;
  &lt;span class="comment"&gt;# This route can be invoked with purchase_url(:id =&amp;gt; product.id)&lt;/span&gt;

  &lt;span class="comment"&gt;# Sample resource route (maps HTTP verbs to controller actions automatically):&lt;/span&gt;
  &lt;span class="comment"&gt;#   map.resources :products&lt;/span&gt;

  &lt;span class="comment"&gt;# Sample resource route with options:&lt;/span&gt;
  &lt;span class="comment"&gt;#   map.resources :products, :member =&amp;gt; { :short =&amp;gt; :get, :toggle =&amp;gt; :post }, :collection =&amp;gt; { :sold =&amp;gt; :get }&lt;/span&gt;

  &lt;span class="comment"&gt;# Sample resource route with sub-resources:&lt;/span&gt;
  &lt;span class="comment"&gt;#   map.resources :products, :has_many =&amp;gt; [ :comments, :sales ], :has_one =&amp;gt; :seller&lt;/span&gt;

  &lt;span class="comment"&gt;# Sample resource route within a namespace:&lt;/span&gt;
  &lt;span class="comment"&gt;#   map.namespace :admin do |admin|&lt;/span&gt;
  &lt;span class="comment"&gt;#     # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)&lt;/span&gt;
  &lt;span class="comment"&gt;#     admin.resources :products&lt;/span&gt;
  &lt;span class="comment"&gt;#   end&lt;/span&gt;

  &lt;span class="comment"&gt;# You can have the root of your site routed with map.root -- just remember to delete public/index.html.&lt;/span&gt;
  &lt;span class="comment"&gt;# map.root :controller =&amp;gt; &amp;quot;welcome&amp;quot;&lt;/span&gt;

  &lt;span class="comment"&gt;# See how all your routes lay out with &amp;quot;rake routes&amp;quot;&lt;/span&gt;

  &lt;span class="comment"&gt;# Install the default routes as the lowest priority.&lt;/span&gt;
  &lt;span class="ident"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;connect&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;:controller/:action/:id&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
  &lt;span class="ident"&gt;map&lt;/span&gt;&lt;span class="punct"&gt;.&lt;/span&gt;&lt;span class="ident"&gt;connect&lt;/span&gt; &lt;span class="punct"&gt;'&lt;/span&gt;&lt;span class="string"&gt;:controller/:action/:id.:format&lt;/span&gt;&lt;span class="punct"&gt;'&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

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


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git add .
&amp;gt; git commit -m 'Merged from comment branch.  Resolved config/routes.rb'
Created commit cfb3b0e: Merged from comment branch.  Resolved config/routes.rb
 8 files changed, 49 insertions(+), 0 deletions(-)
 create mode 100644 app/controllers/comments_controller.rb
 create mode 100644 app/helpers/comments_helper.rb
 create mode 100644 app/models/comment.rb
 create mode 100644 db/migrate/001_create_comments.rb
 create mode 100644 test/fixtures/comments.yml
 create mode 100644 test/functional/comments_controller_test.rb
 create mode 100644 test/unit/comment_test.rb&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

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


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git branch -d posts
Deleted branch posts.
&amp;gt; git branch -d comments
error: The branch 'comments' is not an ancestor of your current HEAD.
If you are sure you want to delete it, run 'git branch -D comments'.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;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.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git branch -D comments
Deleted branch comments.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Lets establish some ActiveRecord relationships.  Before we do that, lets create another branch called relationships.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git branch relationships
&amp;gt; git checkout relationships
Switched to branch &amp;quot;relationships&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Add the one-to-many relationship to post.rb.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Post&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActiveRecord&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;
  &lt;span class="ident"&gt;has_many&lt;/span&gt; &lt;span class="symbol"&gt;:comments&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;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.&lt;/p&gt;


	&lt;p&gt;We use a stash to do that.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git stash save
Saved working directory and index state &amp;quot;WIP on relationships: cfb3b0e... Merged from comment branch.  Resolved config/routes.rb&amp;quot;
HEAD is now at cfb3b0e... Merged from comment branch.  Resolved config/routes.rb&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;The git-stash man page says:&lt;/p&gt;


	&lt;blockquote&gt;
		&lt;p&gt;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 &lt;span class="caps"&gt;HEAD&lt;/span&gt; commit.&lt;/p&gt;
	&lt;/blockquote&gt;


	&lt;p&gt;A few more stash commands.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git stash list
stash@{0}: WIP on relationships: cfb3b0e... Merged from comment branch. Resolved config/routes.rb
&amp;gt; git stash show
 app/models/post.rb |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
&amp;gt; git stash show -p
diff --git a/app/models/post.rb b/app/models/post.rb
index 791dcb5..6ad2382 100644
--- a/app/models/post.rb
+++ b/app/models/post.rb
@@ -1,2 +1,3 @@
 class Post &amp;lt; ActiveRecord::Base
+  has_many :comments
 end&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Our changes are now saved to the stash, as evidenced by running git status.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git status
# On branch relationships
nothing to commit (working directory clean)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Lets fix the urgent bug in the master branch.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git checkout master
Switched to branch &amp;quot;master&amp;quot;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;It turns out the bug is really trivial.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; rm public/index.html
&amp;gt; git commit -a -m 'Fixed urgent bug'
Created commit 9a6dcf7: Fixed urgent bug
 1 files changed, 0 insertions(+), 277 deletions(-)
 delete mode 100644 public/index.html&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;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.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git checkout relationships
Switched to branch &amp;quot;relationships&amp;quot;
&amp;gt; git stash apply
# On branch relationships
# Changed but not updated:
#   (use &amp;quot;git add &amp;lt;file&amp;gt;...&amp;quot; to update what will be committed)
#
#    modified:   app/models/post.rb
#
no changes added to commit (use &amp;quot;git add&amp;quot; and/or &amp;quot;git commit -a&amp;quot;)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Lets finish our relationship modeling by modifying comment.rb&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_ruby "&gt;&lt;span class="keyword"&gt;class &lt;/span&gt;&lt;span class="class"&gt;Comment&lt;/span&gt; &lt;span class="punct"&gt;&amp;lt;&lt;/span&gt; &lt;span class="constant"&gt;ActiveRecord&lt;/span&gt;&lt;span class="punct"&gt;::&lt;/span&gt;&lt;span class="constant"&gt;Base&lt;/span&gt;
  &lt;span class="ident"&gt;belongs_to&lt;/span&gt; &lt;span class="symbol"&gt;:post&lt;/span&gt;
&lt;span class="keyword"&gt;end&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;We are ready to commit our changes now.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git commit -a -m 'Added post-comment relationship'
Created commit f71752b: Added post-comment relationship
 2 files changed, 2 insertions(+), 0 deletions(-)&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;A quick peek at gitk.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://img.skitch.com/20080427-musar19kcq4ftdin6aht12qkaq.png" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;We can merge the relationships branch to the master branch now.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git checkout master
Switched to branch &amp;quot;master&amp;quot;
&amp;gt; git merge relationships
Merge made by recursive.
 app/models/comment.rb |    1 +
 app/models/post.rb    |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
&amp;gt; git branch -d relationships
Deleted branch relationships.&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;We can now clear our stash because we already have the changes.&lt;/p&gt;


&lt;div class="typocode"&gt;&lt;pre&gt;&lt;code class="typocode_default "&gt;&amp;gt; git stash clear&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;

	&lt;p&gt;Final picture.&lt;/p&gt;


	&lt;p&gt;&lt;img src="http://img.skitch.com/20080427-n7u84ucaks6igsqisk3e6mkmkj.png" alt="" /&gt;&lt;/p&gt;


	&lt;p&gt;Yay!&lt;/p&gt;</description>
      <pubDate>Sun, 27 Apr 2008 10:50:00 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:26f903a9-5cfd-4aad-87c5-f9378d5836dc</guid>
      <author>Raymond Law</author>
      <link>http://blog.rayvinly.com/articles/2008/04/27/using-git-branches-and-stash</link>
      <category>Git</category>
      <category>Ruby on Rails</category>
      <category>Web 2.0</category>
      <category>git</category>
      <category>ruby</category>
      <category>rails</category>
      <category>rubyonrails</category>
      <trackback:ping>http://blog.rayvinly.com/articles/trackback/60</trackback:ping>
    </item>
    <item>
      <title>"Using Git Branches and Stash" by Raymond Law</title>
      <description>&lt;p&gt;Gustavo,&lt;/p&gt;


	&lt;p&gt;It depends.  If you are working on a new feature that warrants a new branch, you should do that.  But if you need a new scaffold for the feature that you are already working on in your current branch, I say no.  You can always undo by running script/destroy.&lt;/p&gt;


	&lt;p&gt;Also, if you just forget a column, you can just add it back to the model, migration, controller, view manually.&lt;/p&gt;


	&lt;p&gt;Hope it helps.&lt;/p&gt;</description>
      <pubDate>Mon, 20 Oct 2008 13:21:51 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:b884b819-f1d6-42ff-a01b-72d2bbad2dd0</guid>
      <link>http://blog.rayvinly.com/articles/2008/04/27/using-git-branches-and-stash#comment-17801</link>
    </item>
    <item>
      <title>"Using Git Branches and Stash" by Gustavo Delfino</title>
      <description>&lt;p&gt;So, would you recommend creating a new branch before one runs script/generate?&lt;/p&gt;


	&lt;p&gt;A branch could be used as an &amp;#8220;undo&amp;#8221; for those times when you do &amp;#8220;script/generate scaffold (...)&amp;#8221; and just after running the script you realize that you forgot a column. Then you would delete the branch, create the branch again and run script/generate again.&lt;/p&gt;</description>
      <pubDate>Mon, 13 Oct 2008 11:48:58 -0400</pubDate>
      <guid isPermaLink="false">urn:uuid:f497fc6e-39fc-41cf-b51d-2381f68c05ca</guid>
      <link>http://blog.rayvinly.com/articles/2008/04/27/using-git-branches-and-stash#comment-17266</link>
    </item>
  </channel>
</rss>
