<?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>Robby on Rails: git-svn is a gateway drug</title>
    <link>http://www.robbyonrails.com/articles/2008/04/10/git-svn-is-a-gateway-drug</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>thoughts.sort_by{|t| t[:topic]}.collect </description>
    <item>
      <title>git-svn is a gateway drug</title>
      <description>&lt;p&gt;As we&amp;#8217;re migrating away from Subversion to Git, I&amp;#8217;m having to learn a lot about &lt;code&gt;git-svn&lt;/code&gt;. Andy has &lt;a href="http://andy.delcambre.com/2008/3/4/git-svn-workflow"&gt;posted a few articles&lt;/a&gt; on this topic, but I wanted to share a quick tip that I find myself forgetting.&lt;/p&gt;


	&lt;h2&gt;Working with Subversion branches&lt;/h2&gt;


	&lt;p&gt;While you&amp;#8217;re hopefully already familiar with how great &lt;strong&gt;local branches&lt;/strong&gt; are with Git, you might not know that you can connect local branches to &lt;strong&gt;remote&lt;/strong&gt; branches in your Subversion repository. This allows those of us who are using Git locally to work against Subversion branches.&lt;/p&gt;


	&lt;p&gt;I&amp;#8217;m going to assume the following:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;Your team is using Subversion&lt;/li&gt;
		&lt;li&gt;Your team already has a branch that you&amp;#8217;re working in&lt;/li&gt;
		&lt;li&gt;Your team is following Subversion directory conventions (&lt;code&gt;branches/&lt;/code&gt;, &lt;code&gt;tags/&lt;/code&gt;, and &lt;code&gt;trunk/&lt;/code&gt;)&lt;/li&gt;
		&lt;li&gt;You have Git installed (&lt;em&gt;with &lt;span class="caps"&gt;SVN&lt;/span&gt; extensions&lt;/em&gt;)&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h3&gt;Checkout the Subversion project with Git&lt;/h3&gt;


	&lt;p&gt;Please visit Andy&amp;#8217;s tutorial, &lt;a href="http://andy.delcambre.com/2008/3/4/git-svn-workflow"&gt;Git &lt;span class="caps"&gt;SVN&lt;/span&gt; Workflow&lt;/a&gt;, for a more detailed explanation of the following commands.&lt;/p&gt;


	&lt;p&gt;First, we&amp;#8217;ll initialize your new local Git repository with &lt;code&gt;git-svn&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  git svn init -s http://svn.yourdomain.com/repos/project_name
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Now, you&amp;#8217;ll change directories to your new Git repository.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  cd project_name
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Let&amp;#8217;s fetch all previous revisions into your local repository&lt;sup&gt;&lt;a href="#fn1"&gt;1&lt;/a&gt;&lt;/sup&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  git svn fetch
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;Great, once this is done&amp;#8230; you&amp;#8217;re &lt;strong&gt;master&lt;/strong&gt; (local) branch is linked to &lt;code&gt;trunk/&lt;/code&gt;.&lt;/p&gt;


	&lt;h3&gt;Mapping a local repository to a remote branch&lt;/h3&gt;


	&lt;p&gt;Assuming that your team is working in a Subversion branch on the current iteration of work. Our team has a naming convention for branches for each iteration. For example, if we&amp;#8217;re in Iteration 18, we&amp;#8217;ll write this as &lt;span class="caps"&gt;ITER&lt;/span&gt;-018 everywhere (Basecamp, Lighthouse, Subversion, etc&amp;#8230;). At the start of each iteration, we create a new branch with this naming convention.&lt;/p&gt;


	&lt;p&gt;For &lt;code&gt;ITER-018&lt;/code&gt;, the Subversion branch would be located at:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;http://svn.yourdomain.com/repos/project_name/branches/ITER-018&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;If you were to do a &lt;code&gt;git branch -r&lt;/code&gt;, you should see &lt;code&gt;ITER-018&lt;/code&gt; show up in the list. Now, the one thing that wasn&amp;#8217;t clear when I first read the &lt;code&gt;git-svn&lt;/code&gt; documentation was that you can&amp;#8217;t just checkout that branch with one command. In fact, this has tripped me up a few times.&lt;/p&gt;


	&lt;p&gt;First, you&amp;#8217;ll need to checkout a new &lt;em&gt;local&lt;/em&gt; branch. I&amp;#8217;ve opted to come up with my own convention for &lt;em&gt;local branches&lt;/em&gt; and in this case, I&amp;#8217;ll name it &lt;code&gt;iter_018&lt;/code&gt;.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  git co -b iter_018
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;So, now I&amp;#8217;m in the iter_018 branch, which is local. I&amp;#8217;m currently still mapped to &lt;code&gt;trunk/&lt;/code&gt;, which isn&amp;#8217;t what we want. However, all we need to do is reset where Git is currently pointed to. We can run &lt;a href="http://andy.delcambre.com/2008/3/12/git-reset-in-depth"&gt;git reset&lt;/a&gt; to point this to the &lt;span class="caps"&gt;ITER&lt;/span&gt;-018 branch.&lt;/p&gt;


&lt;pre&gt;&lt;code&gt;
  git reset --hard ITER-018
&lt;/code&gt;&lt;/pre&gt;

	&lt;p&gt;That&amp;#8217;s it! Now, the local &lt;code&gt;iter_018&lt;/code&gt; branch will point to &lt;code&gt;branches/ITER-018&lt;/code&gt; in your Subversion repository. This will allow you to work with your existing repository branch and still reap the benefits of local Git repositories.&lt;/p&gt;


	&lt;h3&gt;What about master?&lt;/h3&gt;


	&lt;p&gt;Good question. The &lt;code&gt;git reset&lt;/code&gt; command that you ran will &lt;span class="caps"&gt;ONLY&lt;/span&gt; apply that that individual local branch. So, master is &lt;em&gt;still&lt;/em&gt; pointing to &lt;code&gt;trunk/&lt;/code&gt;. This will allow you to have several local branches that map to remote branches.&lt;/p&gt;


	&lt;h2&gt;Next Steps&amp;#8230;&lt;/h2&gt;


	&lt;p&gt;If you&amp;#8217;re working with Git already.. great!&lt;/p&gt;


	&lt;p&gt;If you&amp;#8217;re working in an environment that using Subversion, &lt;code&gt;git svn&lt;/code&gt; provides you the ability to start exploring Git without making your entire team switchover. Perhaps your a consultant and working for a client that uses Subversion&amp;#8230; no problem!&lt;/p&gt;


	&lt;p&gt;We&amp;#8217;re still using Subversion for past client projects and are considering &lt;a href="http://github.com"&gt;GitHub&lt;/a&gt;, which &lt;a href="http://github.com/blog/40-we-launched"&gt;just launched (to the public) today&lt;/a&gt; for future projects. A few of us are already using GitHub for open source projects.&lt;/p&gt;


	&lt;p&gt;Fun.. I just saw the following tweet pass by as I began to wrap up this post.&lt;/p&gt;


&lt;div class="thumbnail"&gt;&lt;a href="http://skitch.com/robbyrussell/jeh1/rails-on-github"&gt;&lt;img src="http://img.skitch.com/20080411-rgageidq82ak6ij952ppant4u9.preview.jpg" alt="rails on github" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;span style="font-family: Lucida Grande, Trebuchet, sans-serif, Helvetica, Arial; font-size: 10px; color: #808080"&gt;Uploaded with &lt;a href="http://plasq.com/"&gt;plasq&lt;/a&gt;&amp;#8217;s &lt;a href="http://skitch.com"&gt;Skitch&lt;/a&gt;!&lt;/span&gt;&lt;/div&gt;

	&lt;p&gt;&lt;a href="http://github.com/rails/"&gt;Check out Rails on GitHub!&lt;/a&gt;&lt;/p&gt;


	&lt;h3&gt;The Gateway Drug&amp;#8230; Git reminds me of Cake&lt;/h3&gt;


&lt;object width="425" height="355"&gt;&lt;param name="movie" value="http://www.youtube.com/v/g0GxUxKZdHk&amp;#38;hl=en"&gt;&lt;/param&gt;&lt;param name="wmode" value="transparent"&gt;&lt;/param&gt;&lt;embed src="http://www.youtube.com/v/g0GxUxKZdHk&amp;#38;hl=en" type="application/x-shockwave-flash" wmode="transparent" width="425" height="355"&gt;&lt;/embed&gt;&lt;/object&gt;

	&lt;h3&gt;Questions?&lt;/h3&gt;


	&lt;p&gt;I know that I glossed over a few things, so feel free to post questions and/or tips for others who are looking to dabble with Git.&lt;/p&gt;


	&lt;p id="fn1"&gt;&lt;sup&gt;1&lt;/sup&gt; You&amp;#8217;ll likely have problems if you don&amp;#8217;t have a Git authors file specified in your git config.&lt;/p&gt;
</description>
      <pubDate>Thu, 10 Apr 2008 22:28:00 -0500</pubDate>
      <guid isPermaLink="false">urn:uuid:cea369ee-eed9-4ec3-a0e9-91421f590dd7</guid>
      <author>Robby Russell</author>
      <link>http://www.robbyonrails.com/articles/2008/04/10/git-svn-is-a-gateway-drug</link>
      <category>Ruby on Rails</category>
      <category>Programming</category>
      <category>PLANET ARGON</category>
      <category>git</category>
      <category>rubyonrails</category>
      <category>subversion</category>
      <category>github</category>
    </item>
  </channel>
</rss>
