<?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>Nick Thompson - Occasionally &#187; Software</title>
	<atom:link href="http://feed.nixweb.com/category/software/feed/" rel="self" type="application/rss+xml" />
	<link>http://feed.nixweb.com</link>
	<description></description>
	<lastBuildDate>Tue, 19 Jan 2010 19:38:17 +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>Using Git to sync a website</title>
		<link>http://feed.nixweb.com/2008/11/24/using-git-to-sync-a-website/</link>
		<comments>http://feed.nixweb.com/2008/11/24/using-git-to-sync-a-website/#comments</comments>
		<pubDate>Mon, 24 Nov 2008 21:18:28 +0000</pubDate>
		<dc:creator>Nix</dc:creator>
				<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://feed.nixweb.com/?p=26</guid>
		<description><![CDATA[Git is an extremely powerful tool for file sharing and version control. Unfortunately it is too flexible for most uses &#8211; you need to construct a workflow for your particular usecase, and if you screw things up you may need an expert to help you recover.
I decided that Git was the right tool for maintaining [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://git.or.cz/">Git</a> is an extremely powerful tool for file sharing and version control. Unfortunately it is too flexible for most uses &#8211; you need to construct a workflow for your particular usecase, and if you screw things up you may need an expert to help you recover.</p>
<p>I decided that Git was the right tool for maintaining <a href="http://nixweb.com">nixweb.com</a>, and ran straight into an undocumented use case.  So here I describe the setup and workflow I use for the site, in the hope that it may be useful to somebody. I assume basic familiarity with Git and Ssh.</p>
<p><span id="more-26"></span></p>
<p>The basic setup is that I have two &#8220;non-bare&#8221; repositories, one for the live nixweb.com site and one for development at home. My home machine is behind a firewall, so I need to use <a href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html">git-push</a> to move changes to the live site after they are tested.</p>
<p>The obvious thing to do would be to push from my local master branch to the site&#8217;s master branch. Unfortunately, this operation will screw up the repository on the live site, and you will have to find a Git expert to help you recover. The people who develop Git are aware of this problem but do not plan to fix it, which is one example of why Git is not ready for production use unless you have an expert on staff.</p>
<p>The only safe way to push to a &#8220;non-bare&#8221; repository is hinted at by <a href="http://kerneltrap.org/mailarchive/git/2007/3/19/241732">Junio Hamano in an email message</a>. You need to use <a href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html">git-push</a> to transfer the changes from the home repository to a &#8220;remote&#8221; branch on the production website, then do a separate <a href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html">git-merge</a> on the site to merge the changes into the live tree.</p>
<p>Here&#8217;s how I set up the live site and home development site.  All commands below are executed on the home (development) machine.</p>
<p>First, set up some variables that will be used frequently:</p>
<pre>    # $remoteacct is your account on the production website.
    remoteacct=REMOTEUSER@REMOTEHOST

    # $homesite is the path to the development copy of
    # the site on the local machine
    homesite=~/testsite

    # Now test that ssh and git work on the remote machine.
    # This command may not print anything but it should succeed before
    # going any further.
    ssh $remoteacct git config --list</pre>
<p>Now, initialize the remote git repository.  Here I assume it&#8217;s in ~/public_html on REMOTEHOST.  You probably want hide the ~/public_html/.git directory using .htaccess too.</p>
<pre>    ssh $remoteacct 'cd ~/public_html; git init ; git add .'
    ssh $remoteacct 'git commit -a -m "initial contents"'</pre>
<p>Create the development repository by cloning the site to your home machine.  This <a href="http://www.kernel.org/pub/software/scm/git/docs/git-clone.html">git-clone</a> command also creates the <strong>remotes/site</strong> branch on the home machine to track the state of the production repository, and populates the development area with a copy of the live site. Usually the branch would be called <strong>remotes/origin</strong>, but since we&#8217;re usually going to be pushing rather than pulling, the name &#8220;site&#8221; is less ambiguous.</p>
<pre>    git clone --origin site ssh://$remoteacct/~/public_html $homesite</pre>
<p>Here&#8217;s the unusual step: add a <a href="http://www.kernel.org/pub/software/scm/git/docs/git-config.html">git-config</a> option to allow <a href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html">git-push</a> to work from the home <strong>master</strong> to the live site&#8217;s <strong>remotes/home</strong> area, in addition to the pull setup created by cloning.  Note that &#8220;site&#8221; in the command corresponds to &#8220;&#8211;origin site&#8221; in the git-clone command:</p>
<pre>    cd $homesite
    git config remote.site.push '+refs/heads/*:refs/remotes/home/*'
    git push site</pre>
<p>Now, whenever you need to update the site, you can use <a href="http://www.kernel.org/pub/software/scm/git/docs/git-push.html">git-push</a> to send the latest home commits to the <strong>remotes/home</strong> branch on the live site, and run <a href="http://www.kernel.org/pub/software/scm/git/docs/git-merge.html">git-merge</a> on the live site to bring the changes online.  The &#8220;home&#8221; in the git-merge matches the remotes/home in the git-config command above.</p>
<pre>    git commit -a -m "commit updates in development area"'
    git push site
    ssh $remoteacct 'cd public_html ; git merge home/master'</pre>
<p>To bring changes from the live site to the home repository, they must first be committed on the live site using <a href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html">git-commit</a>. Then use <a href="http://www.kernel.org/pub/software/scm/git/docs/git-pull.html">git-pull</a> to fetch the committed changes  and merge them into the checked out home repository.  You don&#8217;t have to name the remote branch to use in git-pull because it is remembered from &#8220;git-clone &#8211;origin site &#8230;&#8221;.</p>
<pre>    ssh $remoteacct 'cd public_html ; git commit -a -m "commit live site"'
    git pull</pre>
<p>That&#8217;s it! Use at your own risk &#8211; I&#8217;m not a Git expert at this point, but so far it&#8217;s working for me.</p>
]]></content:encoded>
			<wfw:commentRss>http://feed.nixweb.com/2008/11/24/using-git-to-sync-a-website/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
