<?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>A Waage Blog &#187; migrate</title>
	<atom:link href="http://qugstart.com/blog/tag/migrate/feed/" rel="self" type="application/rss+xml" />
	<link>http://qugstart.com/blog</link>
	<description>Ruby, Rails, Life</description>
	<lastBuildDate>Thu, 10 Nov 2011 00:35:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Migrate an SVN repository to Git While Maintaining Branches and Tags Structure</title>
		<link>http://qugstart.com/blog/git-and-svn/migrate-an-svn-repository-to-git-while-maintaining-branches-and-tags-structure/</link>
		<comments>http://qugstart.com/blog/git-and-svn/migrate-an-svn-repository-to-git-while-maintaining-branches-and-tags-structure/#comments</comments>
		<pubDate>Fri, 04 Sep 2009 01:02:32 +0000</pubDate>
		<dc:creator>Andrew Waage</dc:creator>
				<category><![CDATA[Git and SVN]]></category>
		<category><![CDATA[branches]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[migrate]]></category>
		<category><![CDATA[repository]]></category>
		<category><![CDATA[SVN]]></category>
		<category><![CDATA[tags]]></category>
		<category><![CDATA[trunk]]></category>

		<guid isPermaLink="false">http://qugstart.com/blog/?p=8</guid>
		<description><![CDATA[Git is awesome, but for our Rails projects, we like to follow a similar &#8220;centralized repository model&#8221; that SVN makes use of.
We want to use distributed Git repositories, with one central &#8220;shared&#8221; repository to use for deployments, etc.
We don&#8217;t want to use Git with a shared SVN repository. (git-svn)
And, we have a bunch of SVN [...]]]></description>
			<content:encoded><![CDATA[<p>Git is awesome, but for our Rails projects, we like to follow a similar &#8220;centralized repository model&#8221; that SVN makes use of.<br />
We want to use distributed Git repositories, with one central &#8220;shared&#8221; repository to use for deployments, etc.<br />
We don&#8217;t want to use Git with a shared SVN repository. (git-svn)<br />
And, we have a bunch of SVN repositories already that we need to migrate to Git repositories.</p>
<p>I&#8217;ll describe what I did to make this happen:</p>
<p>Notes, quotes, credits all from: <a href="http://notahat.com/posts/25">http://notahat.com/posts/25</a></p>
<p>This is a great post to follow, and accounts for most everything I did here.<br />
The difference is that I&#8217;m using svn2git, instead of doing manual git clone commands.<br />
The above post will only set up remote branches, and what I wanted was to have all branches and tags local to my new Git repository.<br />
Svn2git will copy all of your branches / tags from the original SVN repository into your new Git repository as well.<br />
(Check it out here [thanks to nirvdrum]: <a href="http://github.com/nirvdrum/svn2git/tree/master">http://github.com/nirvdrum/svn2git/tree/master</a>)</p>
<p>Let&#8217;s say I have an SVN repository structured as:</p>
<pre lang="bash" class="prettyprint">trunk
...
branches
1.x
2.x
tags
1.0.0
1.0.1
1.0.2
1.1.0
2.0.0</pre>
<p>Our goal is to have a git repository with native tags/branches taken from our SVN repository.<br />
At the end of my migration, I want my Git repo to look like:</p>
<pre lang="bash"  class="prettyprint">$ git branch
* master
1.x
2.x
$ git tag -l
1.0.0
1.0.1
1.0.2
1.1.0
2.0.0</pre>
<p>#Make sure Git is installed:<br />
#If you don&#8217;t have the epel yum repository enabled by default, you must specify to enable it at the command line:<br />
#For other distributions, you know the drill (apt-get, port, etc.)</p>
<pre lang="bash" class="prettyprint">yum --enablerepo epel install 'git'
yum --enablerepo epel install 'git-svn'</pre>
<p>#Now, create a system git user and group</p>
<pre lang="bash" class="prettyprint">sudo adduser git</pre>
<p>#Now edit /etc/group, and add any users who&#8217;ll need to access the Git repository to the git group:</p>
<pre lang="bash" class="prettyprint">...
git:x:100:james,paul
...</pre>
<p>#Make a directory for Git repositories<br />
#We chose: /usr/local/git_root</p>
<pre lang="bash" class="prettyprint">sudo mkdir /usr/local/git_root
sudo chown git.git /usr/local/git_root
sudo chmod 2770 /usr/local/git_root</pre>
<p>#Create your svn-authors.txt in /usr/local/git_root/svn-authors.txt to tell Git how to convert SVN usernames in the logs:<br />
#Place *ALL* SVN authors in this file so that git doesn&#8217;t complain when it cannot find a particular user to convert.</p>
<p>pbunyan = Paul Bunyan &lt;pbunyan@example.com&gt;<br />
jbond = James Bond &lt;jbond@example.com&gt;</p>
<p>On the left are the Subversion user names; on the right are the Git equivalents.</p>
<p>#Make sure your gem sources include github.com (if necessary)</p>
<pre lang="bash" class="prettyprint">sudo gem sources -a http://gems.github.com</pre>
<p>#Install the svn2git gem</p>
<pre lang="bash" class="prettyprint">sudo gem install nirvdrum-svn2git</pre>
<p>#Verify that you have svn2git in your PATH</p>
<pre lang="bash" class="prettyprint">which svn2git</pre>
<p>#We will create a temporary directory in /tmp/<br />
#This is where we will fetch the SVN repo into a git repo.<br />
#We&#8217;ll then use this temporary repo to create our bare repository.</p>
<pre lang="bash" class="prettyprint">mkdir /tmp/foo-project
cd /tmp/foo-project</pre>
<p>#I&#8217;m assuming you have the standard SVN setup of</p>
<pre lang="bash" class="prettyprint">-root
---trunk
---branches
---tags</pre>
<p>If not, you can look into the options of svn2git to match your SVN repo structure.</p>
<p>#Run the command given your svn-authors file:</p>
<pre lang="bash" class="prettyprint">svn2git https://svn-repo/foo-project --authors /usr/local/git_root/svn-authors.txt</pre>
<p>#You can go into this folder and verify that you see all your local branches and tags by running:</p>
<pre lang="bash" class="prettyprint">git branch
and
git tag -l</pre>
<p>This should print out the lists of your branches and tags if everything is working right so far!</p>
<p>Next, we want to create our bare repository in /usr/local/git_root.</p>
<p>#Become git user and set permissions</p>
<pre lang="bash" class="prettyprint">sudo su - git
cd /usr/local/git_root/
umask 007</pre>
<p>#Clone the temporary repository created by svn2git to a bare repository.<br />
#&lt;project&gt;.git is a local convention.</p>
<pre lang="bash" class="prettyprint">git clone --bare /tmp/foo-project foo-project.git
cd foo-project.git/</pre>
<p>#Make sure permissions are set properly</p>
<pre lang="bash" class="prettyprint">git config core.sharedrepository 1
git config receive.denyNonFastforwards true
find objects -type d -exec chmod 02770 {} \;</pre>
<p>The core.sharedrepository flag tells git to keep everything group readable and writable.<br />
The receive.denyNonFastforwards flag makes sure that merges can&#8217;t happen when you push to the repo. You have to do the merges on your local machine, and then push the result.</p>
<p>#Try to do a git clone from your workstation (another computer)</p>
<pre lang="bash" class="prettyprint">git clone ssh://git-repo:22/usr/local/git_root/foo-project.git</pre>
<p>#Clean up<br />
Once you&#8217;re happy that everything is working, delete the temporary repo that you created in /tmp, and you&#8217;re done!</p>
]]></content:encoded>
			<wfw:commentRss>http://qugstart.com/blog/git-and-svn/migrate-an-svn-repository-to-git-while-maintaining-branches-and-tags-structure/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

