<?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>Stoney's Zone &#187; dreamhost</title>
	<atom:link href="http://stoney.sb.org/wordpress/tag/dreamhost/feed/" rel="self" type="application/rss+xml" />
	<link>http://stoney.sb.org/wordpress</link>
	<description>Thoughts about stuff</description>
	<lastBuildDate>Thu, 24 Dec 2009 16:49:03 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Mirroring git respositories to DreamHost</title>
		<link>http://stoney.sb.org/wordpress/2009/06/mirroring-git-respositories-to-dreamhost/</link>
		<comments>http://stoney.sb.org/wordpress/2009/06/mirroring-git-respositories-to-dreamhost/#comments</comments>
		<pubDate>Thu, 11 Jun 2009 20:16:35 +0000</pubDate>
		<dc:creator>stoney</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[backup]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[shell]]></category>

		<guid isPermaLink="false">http://stoney.sb.org/wordpress/?p=109</guid>
		<description><![CDATA[Casper Fabricius has a nice shell script for creating new git repositories on DreamHost. Unfortunately, this works only for creating new repositories. I already have a lot of local git repositories, and this seemed like a much better way to back them up off-site than using github or similar. This is useful only for repositories [...]]]></description>
			<content:encoded><![CDATA[<p>Casper Fabricius has a <a href="http://casperfabricius.com/site/2008/09/21/keeping-git-repositories-on-dreamhost-using-ssh/">nice shell script</a> for creating new git repositories on DreamHost. Unfortunately, this works only for creating new repositories.</p>
<p><span id="more-109"></span></p>
<p>I already have a lot of local git repositories, and this seemed like a much better way to back them up off-site than using github or similar. This is useful only for repositories without collaborators, of course.</p>
<p>Here&#8217;s the shell script. I used Bash just because that&#8217;s my normal shell.</p>
<p>All disclaimers disclaimed. This is not bulletproof.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Create a mirror of a local git repos on DreamHost.</span>
<span style="color: #666666; font-style: italic;"># Run this in the root directory of an existing git repository.</span>
<span style="color: #666666; font-style: italic;"># Note that this sets the &quot;origin&quot; remote.</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Derived from http://casperfabricius.com/site/2008/09/21/keeping-git-repositories-on-dreamhost-using-ssh/</span>
<span style="color: #666666; font-style: italic;">#</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># change this to your ssh login.</span>
<span style="color: #007800;">DREAMGIT_DOMAIN</span>=user<span style="color: #000000; font-weight: bold;">@</span>domain.com
&nbsp;
<span style="color: #666666; font-style: italic;"># ensure that we're at the top of a git repos</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-d</span> .git <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;The current directory is not a git repository&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #666666; font-style: italic;"># get our directory name and split off the project name</span>
<span style="color: #007800;">dirPath</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">pwd</span><span style="color: #000000; font-weight: bold;">`</span>
<span style="color: #007800;">baseProjectName</span>=<span style="color: #800000;">${dirPath##/*/}</span>
<span style="color: #666666; font-style: italic;"># replace spaces with underscores in the project name</span>
<span style="color: #007800;">projectName</span>=<span style="color: #800000;">${baseProjectName// /_}</span>
<span style="color: #666666; font-style: italic;"># remove any other troublesome characters</span>
<span style="color: #007800;">projectName</span>=<span style="color: #800000;">${projectName//[^-a-zA-Z0-9_.]/}</span>
<span style="color: #666666; font-style: italic;"># make the remote mirror on DreamHost</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span> <span style="color: #007800;">$DREAMGIT_DOMAIN</span> <span style="color: #ff0000;">'mkdir -p ~/git/'</span><span style="color: #007800;">$projectName</span><span style="color: #ff0000;">'.git &amp;&amp; cd ~/git/'</span><span style="color: #007800;">$projectName</span><span style="color: #ff0000;">'.git &amp;&amp; git --bare init'</span>
<span style="color: #666666; font-style: italic;"># set the remote as the default push and pull target</span>
<span style="color: #c20cb9; font-weight: bold;">git</span> remote add origin <span style="color: #660033;">--mirror</span> <span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span><span style="color: #007800;">$DREAMGIT_DOMAIN</span><span style="color: #000000; font-weight: bold;">/</span>~<span style="color: #000000; font-weight: bold;">/</span>git<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$projectName</span>.git
<span style="color: #666666; font-style: italic;"># push all to it</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Pushing everything to remote...&quot;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #c20cb9; font-weight: bold;">git</span> push <span style="color: #660033;">-v</span> origin; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;Git mirror at '<span style="color: #007800;">$DREAMGIT_DOMAIN</span>/git/<span style="color: #007800;">$projectName</span>.git' all set&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;git push failed&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></td></tr></table></div>

<p>I imagine that this will work for any server to which you can ssh.</p>
]]></content:encoded>
			<wfw:commentRss>http://stoney.sb.org/wordpress/2009/06/mirroring-git-respositories-to-dreamhost/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

