<?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>Peter Mac And Associates&#187; Git</title>
	<atom:link href="http://www.petermac.com/category/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.petermac.com</link>
	<description>Australian freelance programmer and website design</description>
	<lastBuildDate>Thu, 17 Nov 2011 22:50:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Setup Git Local and Remote Repositories</title>
		<link>http://www.petermac.com/setup-git-local-and-remote-repositories/</link>
		<comments>http://www.petermac.com/setup-git-local-and-remote-repositories/#comments</comments>
		<pubDate>Tue, 11 Jan 2011 20:19:38 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.petermac.com/?p=562</guid>
		<description><![CDATA[If you are a remote worker or, like me get some work done on the train on the way to/from your office, you&#8217;ll appreciate the need for set up of a local and remote source code repository, This allows you to develop using your laptop/netbook, check in your changes locally and when you arrive at [...]]]></description>
			<content:encoded><![CDATA[<p>If you are a remote worker or, like me get some work done on the train on the way to/from your office, you&#8217;ll appreciate the need for set up of a local and remote source code repository, This allows you to develop using your laptop/netbook, check in your changes locally and when you arrive at the mothership later, you can synchronise your local repository with the remote one ensuring all your changes are available for other developers. This article shows how to set up git for both a mothership type repository (let&#8217;s call it the remote repository) and a local version on your own laptop.</p>
<h2>Configuring Git project on the mothership.</h2>
<p>Prerequisites:</p>
<p>A Git server (the mothership) has been set up on a box called bluelight. This box is available to the network as git.petermac.com.</p>
<p>A git user has been created on the server called &#8216;git&#8217;. This user has access to the folder where the git repositories are stored.</p>
<p>The Steps:</p>
<p>1.On your dev machine create your code project using whatever tools you need.</p>
<p>2.Initialise this working project under the git version control system</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #7a0874; font-weight: bold;">cd</span> ~<span style="color: #000000; font-weight: bold;">/</span>projects<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>myprojectname<span style="color: #7a0874; font-weight: bold;">&#93;</span><br />
$ <span style="color: #c20cb9; font-weight: bold;">git</span> init<br />
peter<span style="color: #000000; font-weight: bold;">@</span>peter-desktop:~<span style="color: #000000; font-weight: bold;">/</span>Projects<span style="color: #000000; font-weight: bold;">/</span>rentmanager$ <span style="color: #c20cb9; font-weight: bold;">git</span> init<br />
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>peter<span style="color: #000000; font-weight: bold;">/</span>Projects<span style="color: #000000; font-weight: bold;">/</span>rentmanager<span style="color: #000000; font-weight: bold;">/</span>.git<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>3.Add whatever work you&#8217;ve done to the repository</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">git</span> add app<span style="color: #000000; font-weight: bold;">/</span><br />
$ <span style="color: #c20cb9; font-weight: bold;">git</span> add docs<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>4.Check the files you want added have been added</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">git</span> status<br />
<span style="color: #666666; font-style: italic;"># On branch master</span><br />
<span style="color: #666666; font-style: italic;"># Initial commit</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
<span style="color: #666666; font-style: italic;"># Changes to be committed:</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; (use &quot;git rm --cached ...&quot; to unstage)</span><br />
<span style="color: #666666; font-style: italic;">#</span><br />
<span style="color: #666666; font-style: italic;"># &nbsp; &nbsp;new file: app/rentmanager/,</span><br />
<span style="color: #666666; font-style: italic;">#</span></div></div>
<p>5.Open a SSH session to bluelight – (the central git repository server)</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gitrepos<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>myprojectname<span style="color: #7a0874; font-weight: bold;">&#93;</span>.git</div></div>
<p>6.Obviously substitute your real projectname and don&#8217;t forget to leave the .git extenstion</p>
<p>7.Initialise the repository under the new folder</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">$cd</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gitrepos<span style="color: #000000; font-weight: bold;">/</span><span style="color: #7a0874; font-weight: bold;">&#91;</span>myprojectname<span style="color: #7a0874; font-weight: bold;">&#93;</span>.git<br />
<br />
<span style="color: #7a0874; font-weight: bold;">&#91;</span>peter<span style="color: #000000; font-weight: bold;">@</span>bluelight myprojectname.git<span style="color: #7a0874; font-weight: bold;">&#93;</span>$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">git</span> init<br />
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gitrepos<span style="color: #000000; font-weight: bold;">/</span>myprojectname.git<span style="color: #000000; font-weight: bold;">/</span>.git<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>8.Change ownership of the repository to the system git user</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">$cd</span> ..; <span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> git.git <span style="color: #660033;">-R</span> <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gitrepos<span style="color: #000000; font-weight: bold;">/</span>myprojectname.git</div></div>
<h2>Configure git on your laptop to use the remote repository</h2>
<p>1. Return back to the local machine and add reference to the new &#8216;remote&#8217; repository from the base directory of the project.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">git</span> remote add remote <span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #c20cb9; font-weight: bold;">git</span> at git.petermac.com<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gitrepos<span style="color: #000000; font-weight: bold;">/</span>myprojectname<span style="color: #7a0874; font-weight: bold;">&#93;</span>.git</div></div>
<p>2. Here the &#8216;git remote add&#8217; part says add a reference to a remote repository. The second &#8216;remote&#8217; is the friendly name I want to use when referring to the repository on the git server</p>
<p>3. Now commit the local files to the local repository – Note: Step 3 was only an add, not a commit.  When you commit you&#8217;ll be prompted (or you can enter it as a -m option) to enter a message to be used as a comment.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">peter<span style="color: #000000; font-weight: bold;">@</span>peter-desktop:~<span style="color: #000000; font-weight: bold;">/</span>Projects<span style="color: #000000; font-weight: bold;">/</span>myprojectname$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit<br />
Created initial commit 633fd3c: initial checkin of project core and data migration files</div></div>
<p>4. It&#8217;s time to test the new remote repository by &#8216;pushing your local repository info up to it. This is done using git push</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">peter<span style="color: #000000; font-weight: bold;">@</span>peter-desktop:~<span style="color: #000000; font-weight: bold;">/</span>Projects<span style="color: #000000; font-weight: bold;">/</span>myprojectname$ <span style="color: #c20cb9; font-weight: bold;">git</span> push –dry-run –all <span style="color: #660033;">--repo</span>=remote<br />
fatal: <span style="color: #ff0000;">'origin'</span>: unable to chdir or not a <span style="color: #c20cb9; font-weight: bold;">git</span> archive<br />
fatal: The remote end hung up unexpectedly</div></div>
<p>Didn&#8217;t quite go to plan – so let&#8217;s see what&#8217;s wrong</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">peter<span style="color: #000000; font-weight: bold;">@</span>peter-desktop:~<span style="color: #000000; font-weight: bold;">/</span>Projects<span style="color: #000000; font-weight: bold;">/</span>myprojectname$ <span style="color: #c20cb9; font-weight: bold;">git</span> remote show remote<br />
The authenticity of host <span style="color: #ff0000;">'git.petermac.com (192.168.0.15)'</span> can<span style="color: #ff0000;">'t be established.<br />
RSA key fingerprint is 5a:ce:6e:a4:78:d5:01:50:36:2b:bb:12:67:e1:be:53.<br />
Are you sure you want to continue connecting (yes/no)? yes<br />
Warning: Permanently added '</span>git.petermac.com<span style="color: #ff0000;">' (RSA) to the list of known hosts.<br />
git at git.petermac.com'</span>s password:<br />
<span style="color: #000000; font-weight: bold;">*</span> remote remote<br />
URL: <span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #c20cb9; font-weight: bold;">git</span> at git.petermac.com<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gitrepos<span style="color: #000000; font-weight: bold;">/</span>myprojectname.git</div></div>
<p>let&#8217;s try again</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">git</span> push –dry-run –all –<span style="color: #007800;">repo</span>=remote<br />
<span style="color: #c20cb9; font-weight: bold;">git</span> at git.petermac.com<span style="color: #ff0000;">'s password:<br />
To ssh://git at git.petermac.com/usr/local/share/gitrepos/myprojectname.git<br />
[new branch] &nbsp; &nbsp; &nbsp;master -&amp;gt; master</span></div></div>
<p>looks like it will work so remove the dry-run parameter</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">$ <span style="color: #c20cb9; font-weight: bold;">git</span> push –all –<span style="color: #007800;">repo</span>=remote</div></div>
<p>That&#8217;s all folks!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.petermac.com%2Fsetup-git-local-and-remote-repositories%2F&amp;title=Setup%20Git%20Local%20and%20Remote%20Repositories" id="wpa2a_2"><img src="http://www.petermac.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.petermac.com/setup-git-local-and-remote-repositories/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Internationalized country/state/city database</title>
		<link>http://www.petermac.com/internationalized-countrystatecity-database/</link>
		<comments>http://www.petermac.com/internationalized-countrystatecity-database/#comments</comments>
		<pubDate>Wed, 28 Jul 2010 10:37:11 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Databases]]></category>
		<category><![CDATA[Git]]></category>
		<category><![CDATA[Ruby on Rails]]></category>

		<guid isPermaLink="false">http://www.petermac.com/?p=292</guid>
		<description><![CDATA[I&#8217;ve just posted a little project up to the gitorious website for my and other&#8217;s pleasure. The last few freelance projects I&#8217;ve worked on have required the functionality to provide users with a way to enter their location using a prompt system by selecting country first, then entering their region/state and finally their town and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve just posted a little project up to the gitorious website for my and other&#8217;s pleasure. The last few freelance projects I&#8217;ve worked on have required the functionality to provide users with a way to enter their location using a prompt system by selecting country first, then entering their region/state and finally their town and city. The database structure uses a standard Rails convention and is MySQL based. It can be very easily converted to any other SQL supported format.</p>
<p>
<a href="http://gitorious.org/internationalised-country-city-region-database" target="blank">Click here to browse to the project.</a></p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.petermac.com%2Finternationalized-countrystatecity-database%2F&amp;title=Internationalized%20country%2Fstate%2Fcity%20database" id="wpa2a_4"><img src="http://www.petermac.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.petermac.com/internationalized-countrystatecity-database/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Moving from Subversion to Git</title>
		<link>http://www.petermac.com/moving-from-subversion-to-git/</link>
		<comments>http://www.petermac.com/moving-from-subversion-to-git/#comments</comments>
		<pubDate>Sat, 10 Jul 2010 03:47:22 +0000</pubDate>
		<dc:creator>peter</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[GNU/Linux]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://www.petermac.com/?p=239</guid>
		<description><![CDATA[I have been using subversion for a number of years and it wasn&#8217;t until I had seen and sampled the simplicity and power of git that I decided once and for all to bite the bullet and migrate all my subversion repositories to git. I&#8217;d done the same from cvs to subversion in the early [...]]]></description>
			<content:encoded><![CDATA[<p>I have been using subversion for a number of years and it wasn&#8217;t until I had seen and sampled the simplicity and power of git that I decided once and for all to bite the bullet and migrate all my subversion repositories to git.</p>
<p>I&#8217;d done the same from cvs to subversion in the early 2000&#8242;s and still think the move worked out well with a bit of preparation.</p>
<p>An unfortunate side effect of subversion is that it takes a good bit of effort to set up and manage a new repository so I ended up with two somewhat monolithic repositories&#8230;</p>
<p>1. archives<br />
2. projects</p>
<p>The &#8216;archives &#8216; repository contained all old project work and the &#8216;projects&#8217; one contained relevant or current project work.</p>
<p>The result of this was that each archive had a bundle of sub-folders, each containing a project in its&#8217; own right. Although git can handle the concept of sub-modules it&#8217;s not the best way to structure your project. In fact, it was a pretty lazy to structure my subversion projects in the first place but convenience overcame system administrative chores at the time.</p>
<p>This article explains the following:</p>
<p>1. Converting a monolithic subversion repository to a git repository<br />
2. Breaking out the new git repository into a set of discrete repositories.<br />
3. General backup process and scripts to copy the new repositories across to a backup system.</p>
<p>First off, a couple of conventions I keep are&#8230;</p>
<p>My server stores a central set of repositories with the name of myproject.git<br />
My workstations work with their local version of repositories called myproject (no .git)<br />
My server exports it&#8217;s .git repositories to a backup server using the same .git naming convention.<br />
I have created a git.git user.group on my server to run all git processes. File ownership is given to this user so other users can&#8217;t fowl things up at least without thinking about it first.</p>
<p><strong>Step 1 &#8211; Migrating to git from Subversion</strong></p>
<p>I store all my git repositories on a server in the directory</p>
<p>/usr/local/share/gitrepos</p>
<p>All of my subversion repositories are stored in</p>
<p>/usr/local/share/svn</p>
<p>Even though each folder is accessible using standard paths and commands, I have to go through the subversion door using the same mechanism I would access it from a remote box, namely http://.  Other people may use svn:// if that&#8217;s their way of working.</p>
<p>Migration is taken care of with a single command.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">git</span> <span style="color: #c20cb9; font-weight: bold;">svn</span> clone https:<span style="color: #000000; font-weight: bold;">//</span>localhost<span style="color: #000000; font-weight: bold;">/</span>repository<span style="color: #000000; font-weight: bold;">/</span>projects <span style="color: #660033;">--stdlayout</span> <span style="color: #660033;">--authors-file</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span>peter<span style="color: #000000; font-weight: bold;">/</span>authors.txt <span style="color: #660033;">-t</span> tags <span style="color: #660033;">-b</span> branches <span style="color: #660033;">-T</span> trunk <span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gitrepos<span style="color: #000000; font-weight: bold;">/</span>projects.git<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>An explanation of all the bits follow:</p>
<p><strong>sudo</strong> &#8211; because I run everything as unprivileged user, sudo gives me the rights i need to create new files and folders.</p>
<p><strong>git svn</strong> &#8211; this is the git subcommand that manages conversion of subversion repositories.</p>
<p><strong>clone</strong> &#8211; make a copy of the repositories that I&#8217;m pointing at.</p>
<p><strong>https://localhost/repository/projects</strong> &#8211; I access all my subversion repositories using secure http. This allows me to securely browse the content across the Internet and track things easily using Trac.</p>
<p>Depending on your setup, this parameter will contain the path to your svn repository,however you access it.</p>
<p><strong>&#8211;stdlayout</strong> option tells git svn that my subversion repository is in the standard layout of trunk/branch/tags directories.</p>
<p><strong>&#8211;authors file</strong> &#8211; this is a file I created by hand containing a list of all the people who committed project material in the past. It&#8217;d format is as follows:</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #007800;">peter</span>= Peter Mac Giollafhearga <span style="color: #000000; font-weight: bold;">&lt;</span>my email at mydomain.com<span style="color: #000000; font-weight: bold;">&gt;</span><br />
<span style="color: #007800;">simon</span>= Simon Shagwell <span style="color: #000000; font-weight: bold;">&lt;</span>simon<span style="color: #000000; font-weight: bold;">\'</span>s email at his domain.com<span style="color: #000000; font-weight: bold;">&gt;</span></div></div>
<p><strong>-t tags -b branches -T trunk</strong> &#8211; these values are for completeness and I&#8217;m not sure they are necessary given the &#8211;stdlayout option, but if you&#8217;ve called your branches, tags and trunks anything different, this is how you find it.</p>
<p>Once the command has completed you should find a projects.git folder has been created and navigating into it you will see all your nasty subversion sub-folders which you should have set up as individual repositories in the first place&#8230;tut tut!</p>
<p><strong>Step 2 &#8211; Breaking out Git into baby gits</strong></p>
<p>The structure of the new git repository is something like this.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gitrepository<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; projects.git<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; &nbsp; project1<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; &nbsp; WorldDomination<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; &nbsp; SomeStuff<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; &nbsp; SomeotherStuff_V2<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; &nbsp; Demos<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; &nbsp; Downloads<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; &nbsp; .git<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>The .git folder (you cans see it using ls -a) contains a list of all the git related material such as project history, revisions and tags.<br />
Check you can see your history by typing</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #c20cb9; font-weight: bold;">git</span> log</div></div>
<p>The next task is to break the contents of the rather large &#8216;project&#8217; folder into a git repository per project.<br />
The tool for the job is a combination of the very useful git subtree command and a bit of custom shell scripting specific to this job.</p>
<p>The subtree functionality was written by Avery Pennarun and is hosted by the github site. You can download the git subtree command from the URL <a href="http://github.com/apenwarr/git-subtree" target="blank">http://github.com/apenwarr/git-subtree</a>. Installation instructions are on the same site so I won&#8217;t bore you with it here.</p>
<p>Once you have it installed you&#8217;re almost ready to roll. The following shell script has comments at the top to explain what it does. Save this to your favourite scripts folder and chmod it so it&#8217;s executable (chmod +x git_breakout.sh).</p>
<p>Then cd into the folder you created earlier (in my case /usr/local/share/gitrepository/projects). Run the script and watch the output. Depending on the size of your projects it will take a bit of time to complete; mine took about 20 minutes.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/sh</span><br />
<br />
<span style="color: #666666; font-style: italic;">#git_breakout.sh</span><br />
<span style="color: #666666; font-style: italic;">#This script should be run from within a git repository folder that</span><br />
<span style="color: #666666; font-style: italic;">#contains many child folders.</span><br />
<span style="color: #666666; font-style: italic;">#It will create a branch for every subfolder it finds and a new</span><br />
<span style="color: #666666; font-style: italic;">#top level folder for each.</span><br />
<span style="color: #666666; font-style: italic;">#It then initialises a git respoitory, copying into the relevant branch</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Make sure only root can run our script</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(id -u)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;This script must be run as root&quot;</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span><br />
&nbsp; <span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #007800;">current_dir</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${PWD##*/}</span><span style="color: #000000; font-weight: bold;">`</span><br />
<span style="color: #007800;">git_user</span>=<span style="color: #c20cb9; font-weight: bold;">git</span><br />
<span style="color: #007800;">git_group</span>=<span style="color: #c20cb9; font-weight: bold;">git</span><br />
<br />
<span style="color: #000000; font-weight: bold;">for</span> project <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> . <span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$project</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #007800;">project_lower</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$project</span>.git <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>A-Z<span style="color: #7a0874; font-weight: bold;">&#93;</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>a-z<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #000000; font-weight: bold;">`</span><br />
&nbsp; &nbsp; <span style="color: #007800;">branchname</span>=<span style="color: #007800;">$project_lower</span>.<span style="color: #ff0000;">&quot;export&quot;</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;performing subtree split...&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">git</span> subtree <span style="color: #c20cb9; font-weight: bold;">split</span> <span style="color: #660033;">-P</span> <span style="color: #007800;">$project</span> <span style="color: #660033;">-b</span> <span style="color: #007800;">$branchname</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> ..<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$project_lower</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$project_lower</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;initialising git&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">git</span> init<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;fetching branch&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">git</span> fetch ..<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$current_dir</span> <span style="color: #007800;">$branchname</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">-b</span> master FETCH_HEAD <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> ..<br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;setting appropriate ownership&quot;</span><br />
&nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #007800;">$git_user</span>.<span style="color: #007800;">$git_group</span> <span style="color: #660033;">-R</span> <span style="color: #007800;">$project_lower</span><br />
&nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$current_dir</span><br />
&nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">done</span></div></div>
<p>Once the script has completed, you should be able to see a new directory structure, something along the following lines.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">gitrepository<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; projects.git<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; project1.git<br />
&nbsp; worlddomination.git<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; somestuff.git<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; someotherstuff_v2.git<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; demos.git<span style="color: #000000; font-weight: bold;">/</span><br />
&nbsp; downloads.git<span style="color: #000000; font-weight: bold;">/</span></div></div>
<p>Each folder is now its&#8217; own git repository with it&#8217;s own internal version history, tags, branches etc.<br />
cd into one of the folders and do a git log just to confirm you still have history.</p>
<p>The original projects.git can be removed (after backing it up for safety&#8217;s sake) if you&#8217;re satisfied everything is in place. We&#8217;re now ready to proceed with the next stage of the game, namely backing up our new git repositories to a remote share.</p>
<p><strong>Step 3 &#8211; Backing up Git</strong></p>
<p>I use a 2TB removable disk as a central data server for sharing files throughout my network. My thinking is that should the place ever burn down and I have the opportunity, there&#8217;s only one box I need to grab before rushing out the door. Of course, I burn frequent snapshots of this box to DVD.</p>
<p>I have created a &#8216;backups&#8217; share on the disk which I map to my physical server using NFS.</p>
<p>The entry in my /etc/fstab file is something like this.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">192.168.0.20:<span style="color: #000000; font-weight: bold;">/</span>DataVolume<span style="color: #000000; font-weight: bold;">/</span>backups &nbsp;<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>backups &nbsp;nfs defaults&nbsp; &nbsp; <span style="color: #000000;">0</span> <span style="color: #000000;">0</span></div></div>
<p>This means I can read/write to my backups folder as if it was a local folder on a local disk.</p>
<p>The job at hand is to be able to backup my git repositories using a cron task scheduled to run when everything is nice and quiet. Below is the script I use to run my git backups.</p>
<div class="codecolorer-container bash blackboard" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="bash codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #666666; font-style: italic;">#!/bin/bash</span><br />
<span style="color: #666666; font-style: italic;"># git_backup.sh</span><br />
<span style="color: #666666; font-style: italic;"># Backup git repositories to another folder</span><br />
&nbsp;<br />
<span style="color: #666666; font-style: italic;"># Make sure only root can run our script</span><br />
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$(id -u)</span>&quot;</span> <span style="color: #000000; font-weight: bold;">!</span>= <span style="color: #ff0000;">&quot;0&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;This script must be run as root&quot;</span> <span style="color: #000000;">1</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">2</span><br />
&nbsp; &nbsp;<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span><br />
<span style="color: #000000; font-weight: bold;">fi</span><br />
<br />
<span style="color: #007800;">git_command</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">git</span><br />
<span style="color: #666666; font-style: italic;">#Where they're going to be backed up</span><br />
<span style="color: #007800;">backup_dir</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>backups<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">git</span><br />
<span style="color: #666666; font-style: italic;">#Location of current live repositories</span><br />
<span style="color: #007800;">repository_dir</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>local<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span>gitrepos<br />
<br />
<span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$repository_dir</span><br />
<span style="color: #000000; font-weight: bold;">for</span> project <span style="color: #000000; font-weight: bold;">in</span> $<span style="color: #7a0874; font-weight: bold;">&#40;</span> <span style="color: #c20cb9; font-weight: bold;">ls</span> . <span style="color: #7a0874; font-weight: bold;">&#41;</span><br />
<span style="color: #000000; font-weight: bold;">do</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$project</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; <span style="color: #007800;">destination</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$backup_dir</span>/<span style="color: #007800;">$project</span>&quot;</span><br />
<br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-d</span> <span style="color: #007800;">$destination</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$destination</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;pulling <span style="color: #007800;">$project</span>...&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #007800;">$git_command</span> pull<br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #007800;">$repository_dir</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">else</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;mkdir <span style="color: #007800;">$destination</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #c20cb9; font-weight: bold;">mkdir</span> <span style="color: #007800;">$destination</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">$repository_dir</span>/<span style="color: #007800;">$project</span>&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;cloning <span style="color: #007800;">$project</span>...&quot;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #007800;">$git_command</span> clone <span style="color: #660033;">-v</span> <span style="color: #660033;">-l</span> <span style="color: #660033;">--no-hardlinks</span> . <span style="color: #007800;">$destination</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">cd</span> ..<br />
&nbsp; &nbsp; &nbsp; <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;done.&quot;</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
&nbsp; &nbsp; <span style="color: #000000; font-weight: bold;">fi</span><br />
<span style="color: #000000; font-weight: bold;">done</span></div></div>
<p>Once this script is run, you &#8216;ll have a copy of all your repositories in the backup folder. The next time it&#8217;s run should only take a fraction of the time as it won&#8217;t have to reestablish the git repository again. </p>
<p>So there you have it, migrating a subversion repository to git is really simple, the fun starts when you try to play with the results. I hope this has been helpful to others faced with the same job. Any improvements please let me know.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.petermac.com%2Fmoving-from-subversion-to-git%2F&amp;title=Moving%20from%20Subversion%20to%20Git" id="wpa2a_6"><img src="http://www.petermac.com/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://www.petermac.com/moving-from-subversion-to-git/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

