<?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>blogt0sk1 &#187; Git</title>
	<atom:link href="http://blog.jerodsanto.net/category/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jerodsanto.net</link>
	<description>with Jerod Santo</description>
	<lastBuildDate>Sat, 19 Jun 2010 14:34:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Amending Git Commits</title>
		<link>http://blog.jerodsanto.net/2009/08/amending-git-commits/</link>
		<comments>http://blog.jerodsanto.net/2009/08/amending-git-commits/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 13:31:09 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[quickies]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=581</guid>
		<description><![CDATA[I recently learned that you can fix you&#8217;re previous commit (modify commit message, add more files, etc.) quite easily with git. An example: You&#8217;re in early stages of developing a Rails app and you decide that you want to go back and add some indexes to your tables. No need to create a new migration [...]]]></description>
			<content:encoded><![CDATA[<p>I recently learned that you can fix you&#8217;re previous commit (modify commit message, add more files, etc.) quite easily with git. An example:</p>
<p>You&#8217;re in early stages of developing a Rails app and you decide that you want to go back and add some indexes to your tables. No need to create a new migration at this point, just add the indexes to the old migrations and run them again. After making the changes, you create a commit</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">git commit -a -m &quot;Added missing indexes to tables&quot;</pre></div></div>

<p>Next you re-run all your migrations to get the indexes in there.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">rake db:migrate:reset</pre></div></div>

<p>At this point, you check git status and remember that now your schema file has changed. This probably should have been included in the last commit! Piece of cake.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">git commit db/schema.rb --amend</pre></div></div>

<p>You&#8217;ll be prompted to optionally change the commit message.</p>
<p>At this point git status will tell you that your working directory is clean and the changes to your schema were tracked in the same commit as the migration changes.</p>
<p>Butter.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/08/amending-git-commits/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dead Simple Rails Deployment</title>
		<link>http://blog.jerodsanto.net/2009/05/dead-simple-rails-deployment/</link>
		<comments>http://blog.jerodsanto.net/2009/05/dead-simple-rails-deployment/#comments</comments>
		<pubDate>Sun, 31 May 2009 22:45:28 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[deployment]]></category>
		<category><![CDATA[passenger]]></category>
		<category><![CDATA[rails]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=399</guid>
		<description><![CDATA[Deploying a Rails app used to suck. Reverse proxies, Mongrel clusters, Monit, etc. Capistrano helped out a lot (once you set it up the first time), but all in all the process was still pretty painful. Thankfully, a couple of technologies have come along and made my deployment process a whole lot easier. Passenger This [...]]]></description>
			<content:encoded><![CDATA[<p>Deploying a Rails app used to suck. Reverse proxies, Mongrel clusters, Monit, etc. <a href="http://www.capify.org/">Capistrano</a> helped out a lot (once you set it up the first time), but all in all the process was still pretty painful.</p>
<p>Thankfully, a couple of technologies have come along and made my deployment process a whole lot easier.<br />
<span id="more-399"></span></p>
<ol>
<li><a href="http://modrails.com/">Passenger</a></li>
<p>This was the big one. The <a href="http://www.phusion.nl/">Phusion</a> guys&#8217; &#8220;Hello World&#8221; app (as they called it) has really had a positive impact on the Rails community, and me personally. Suddenly my Rails (and Rack) web apps are first class citizens to Apache (and Nginx), which means I can just point a virtual host at the public directory and go. I had almost forgotten how good it feels to just drop some files in a directory and have Apache serve them.</p>
<li><a href="http://git-scm.com">Git</a></li>
<p>Ok, so maybe Subversion allows a similar workflow, but for some reason Git is one of those tools that is so much fun to use that it makes me think of <a href="http://blog.jerodsanto.net/2009/05/git-informed-when-your-site-is-hacked/">different ways</a> I can use it.
</ol>
<h2>My Flow</h2>
<p>How I deploy these days (when I&#8217;m not deploying to <a href="http://blog.jerodsanto.net/2009/05/3-reasons-why-heroku-is-a-game-changer/">Heroku</a>) is dead simple. I host my private Git repos using <a href="http://eagain.net/gitweb/?p=gitosis.git;a=summary">Gitosis</a>, but the same would work with <a href="http://github.com">GitHub</a> or any Git server.</p>
<h3>Initial Setup</h3>
<ol>
<li>Clone the repository on production server.</li>
<li>Create database.yml and any other production-specific configs</li>
<li>Configure an Apache virtual host pointing to &#8220;public&#8221; folder of the repository</li>
</ol>
<h3>Deploys</h3>
<ol>
<li><strong>locally:</strong>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">git push origin master</pre></div></div>

</li>
<li><strong>remotely:</strong>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">git pull origin master &amp;&amp; touch tmp/restart.txt</pre></div></div>

</li>
</ol>
<p>I know what you&#8217;re thinking, &#8220;Wow, that <em>is</em> dead simple&#8221;. It&#8217;s even easier by using Capistrano to execute the remote commands. Here is an example Capistrano task from one of my Rails apps:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">task <span style="color:#ff3333; font-weight:bold;">:deploy</span>, <span style="color:#ff3333; font-weight:bold;">:roles</span>  <span style="color: #000;">=&gt;</span> <span style="color:#ff3333; font-weight:bold;">:production</span> <span style="color: #000; font-weight: bold;">do</span>
  <span style="color: #0086B3;">system</span> <span style="color: #D14;">&quot;git push origin master&quot;</span>
  cmd = <span style="color: #000;">&#91;</span> <span style="color: #D14;">&quot;cd #{root_dir}&quot;</span>, <span style="color: #D14;">&quot;git pull&quot;</span>, <span style="color: #D14;">&quot;touch tmp/restart.txt&quot;</span> <span style="color: #000;">&#93;</span>
  run cmd.<span style="color: #0086B3;">join</span><span style="color: #000;">&#40;</span><span style="color: #D14;">&quot; &amp;&amp; &quot;</span><span style="color: #000;">&#41;</span>
<span style="color: #000; font-weight: bold;">end</span></pre></div></div>

<p>This task can be extended to automatically install required gems, update Git submodules, migrate the database, and so on.</p>
<h3>Other Benefits</h3>
<p>Besides the simplicity and ease of deployment in this process, I have also enjoyed the ability to make edits in production and pull them back in to my development environment. And because my production environment has a complete history of code changes, it is trivial to revert commits that cause major problems.</p>
<p>This work flow is by no means a panacea. How do you handle deployment?</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/05/dead-simple-rails-deployment/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Rename A Gitosis Repository</title>
		<link>http://blog.jerodsanto.net/2009/05/rename-a-gitosis-repository/</link>
		<comments>http://blog.jerodsanto.net/2009/05/rename-a-gitosis-repository/#comments</comments>
		<pubDate>Thu, 28 May 2009 12:49:36 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[gitosis]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=403</guid>
		<description><![CDATA[I use gitosis for private git repository hosting (and it&#8217;s awesome). If you are interested, this great tutorial will walk you through setting it up yourself. I recently needed to rename one of my repositories and couldn&#8217;t find any info on how to do it, so here is a walk-thru. I will demonstrate the steps [...]]]></description>
			<content:encoded><![CDATA[<p>I use <a href="http://eagain.net/gitweb/?p=gitosis.git;a=summary">gitosis</a> for private git repository hosting (and it&#8217;s awesome). If you are interested, this<a href="http://scie.nti.st/2007/11/14/hosting-git-repositories-the-easy-and-secure-way"> great tutorial</a> will walk you through setting it up yourself.</p>
<p>I recently needed to rename one of my repositories and couldn&#8217;t find any info on how to do it, so here is a walk-thru. I will demonstrate the steps of renaming a repository called &#8220;<strong>tk</strong>&#8221; to &#8220;<strong>show-time</strong>&#8220;.</p>
<ol>
<li>Rename project in gitosis.conf and push changes</li>
<p>Before:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">[group main]
writable = tk</pre></div></div>

<p>After:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">[group main]
writable = show-time</pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">git push origin master</pre></div></div>

<li>Connect to gitosis server and rename correct folder</li>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">cd /home/git/repositories
mv tk show-time</pre></div></div>

<li>Change the remote reference in all repository clones</li>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">cd /src/show-time
git remote rm origin
git remote add origin git@example-git-server.com:show-time.git</pre></div></div>

</ol>
<p>Done and done.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/05/rename-a-gitosis-repository/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Git Informed When Your Site Is Hacked</title>
		<link>http://blog.jerodsanto.net/2009/05/git-informed-when-your-site-is-hacked/</link>
		<comments>http://blog.jerodsanto.net/2009/05/git-informed-when-your-site-is-hacked/#comments</comments>
		<pubDate>Tue, 05 May 2009 02:02:03 +0000</pubDate>
		<dc:creator>Jerod</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://blog.jerodsanto.net/?p=253</guid>
		<description><![CDATA[Good security require defense in depth. The more security layers you add, the harder it is to subvert them all. Here is a reactionary layer you can add to your security practices. The only thing worse than getting hacked is getting hacked and not knowing it (or worse yet, having one of your clients inform [...]]]></description>
			<content:encoded><![CDATA[<p>Good security require <a href="http://en.wikipedia.org/wiki/Defense_in_Depth_(computing)">defense in depth</a>. The more security layers you add, the harder it is to subvert them all. Here is a reactionary layer you can add to your security practices.</p>
<p>The only thing worse than getting hacked is getting hacked and not knowing it (or worse yet, having one of your clients inform you). Often times an attacker needs to add and/or change files on your site to accomplish their goal. Wouldn&#8217;t it be nice if something could inform you of unauthorized changes? Enter <a href="http://git-scm.com/">Git</a>.</p>
<p>I will demonstrate using Git for change notification on a WordPress install using Ruby, but you can apply this principle in many scenarios (hmm, /etc&#8230;?).<br />
<span id="more-253"></span><br />
<strong>1) ignore folders/directories of no interest</strong><br />
We don&#8217;t want Git to track every file in the directory, so we&#8217;ll tell it which ones to ignore. Common choices are temporary directories, log files, and any file or directory that gets update frequently. Create a file called .gitignore in your site&#8217;s root directory. List the stuff for Git to ignore in it. It should look something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">wp-content/cache/*
wp-content/uploads/*</pre></div></div>

<p><strong>2) create new Git repository, add all files and execute first commit</strong></p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">git init
git add .
git commit -a -m &quot;Initial Commit&quot;</pre></div></div>

<p>Now you&#8217;re set.</p>
<p><strong>3) download &#038; customize script</strong><br />
Git alone won&#8217;t check itself and email you. For this, we&#8217;ll need help of a scripting language. I wrote this little script in Ruby, but the same could be accomplished in Bash, Python, or whatever suits your fancy. You can write your own or download and customize the one I use:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">wget http://jerodsanto.net/src/ruby/git_watch.rb
chmod +x git_watch.rb</pre></div></div>

<p>The key to the script is where it shells out and runs the &#8216;git status&#8217; command. If there have been changes to the repository that were not properly committed, &#8216;git status&#8217; will not return &#8220;working directory clean&#8221;. The check is simple:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;">result = <span style="color: #D14;">`git status`</span>
<span style="color: #000; font-weight: bold;">unless</span> result =~ <span style="color: #000;">/</span>working directory clean<span style="color: #000;">/</span>
  <span style="color: #6F6F6F;"># set up email</span>
  send_email SEND_TO, <span style="color:#ff3333; font-weight:bold;">:body</span>  <span style="color: #000;">=&gt;</span> message
<span style="color: #000; font-weight: bold;">end</span></pre></div></div>

<p>You&#8217;ll need to edit this file and change the SEND_TO variable to your email address. You can also customize the email that is sent by modifying the &#8220;send_email&#8221; function near the top.</p>
<p><strong>4) schedule script execution</strong></p>
<p>Now, lets make this script check the blog for changes once every hour. Edit your user&#8217;s cron configuration and add a line similar to this:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">0 * * * * /scripts/git_watch.rb /var/www/mysite/wordpress</pre></div></div>

<p>I put all my custom scripts in a /scripts directory on every server I administer. That way I always know where to look no matter what server I&#8217;m currently on. The script takes one argument, the directory to check for changes. Adjust your cron for your script and site locations.</p>
<p>But what about authorized changes? Simple. Commit them using Git and they won&#8217;t be triggered on.</p>
<p>For example, you install a new plugin to your blog and you don&#8217;t want your git_watch script to email you about it:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">git add wp-content/plugins/github-widget/
git commit -a -m &quot;installed github widget plugin&quot;</pre></div></div>

<p>The added bonus of this technique is you are creating a verifiable changelog of your site over time, complete with notes! An example from one of my sites:</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family:monospace;">git log
&nbsp;
commit 109d30026118de089297a4d7fa56babff3677bdc
Author: Jerod Santo &lt;jerod.santo@gmail.com&gt;
Date:   Sat May 2 07:55:08 2009 -0700
&nbsp;
    fixed bad php4 install and upgraded wp-cache
&nbsp;
commit edc1e89c2cbf38ae1373f6b5cf03d29942399fd8
Author: Jerod Santo &lt;jerod.santo@gmail.com&gt;
Date:   Fri Apr 10 06:25:31 2009 -0700
&nbsp;
    ignore sitemap changes</pre></div></div>

<p>Plus, it is easy to trace the attacker&#8217;s steps if you do get compromised because you can see which files have been changed and what has been done to them (using the &#8216;git diff&#8217; command). Once you diagnose the problem, you can simply revert to an old commit before the attack (you&#8217;re still vulnerable at this point, but at least your site is clean until you can patch it).</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.jerodsanto.net/2009/05/git-informed-when-your-site-is-hacked/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>
