<?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>tail -f development.log &#187; git</title>
	<atom:link href="http://craigjolicoeur.com/blog/category/git/feed" rel="self" type="application/rss+xml" />
	<link>http://craigjolicoeur.com/blog</link>
	<description>code with a purpose</description>
	<lastBuildDate>Sun, 19 Jun 2011 13:25:37 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=abc</generator>
		<item>
		<title>Rails plugin install from specific git branch</title>
		<link>http://craigjolicoeur.com/blog/rails-plugin-install-from-specific-git-branch</link>
		<comments>http://craigjolicoeur.com/blog/rails-plugin-install-from-specific-git-branch#comments</comments>
		<pubDate>Tue, 19 May 2009 18:07:55 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[plugins]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[rubyonrails]]></category>

		<guid isPermaLink="false">http://craigjolicoeur.com/blog/?p=100</guid>
		<description><![CDATA[How to install a rails plugin from a specific tag or branch in a git repository]]></description>
			<content:encoded><![CDATA[<p>Recently while working on a Ruby on Rails plugin, I came across the need to install the plugin from a specific git branch instead of the default master branch.</p>
<pre class="brush: bash; light: true;">
./script/plugin install -h
</pre>
<p>yielded the helpful information I needed.  Last July, <a href="http://github.com/rails/rails/commit/5c086070824bf7dd2bc4c9ce97956d82ac3fa206">a patch was committed</a> to Rails that added the -r ( or &#8211;revision ) parameter.</p>
<p>The -r parameter will take either the name of a git branch or a tag string to checkout instead of the default master branch.</p>
<p>So issuing the following command:</p>
<pre class="brush: bash; light: true;">
./script/plugin install git://github.com/cpjolicoeur/my_plugin.git -r BRANCH_NAME
</pre>
<p>will checkout the BRANCH_NAME branch of the git repository.</p>
<p>Very helpful when testing and debugging new features and bugfixes in a plugin. </p>
]]></content:encoded>
			<wfw:commentRss>http://craigjolicoeur.com/blog/rails-plugin-install-from-specific-git-branch/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>My bash history</title>
		<link>http://craigjolicoeur.com/blog/my-bash-history</link>
		<comments>http://craigjolicoeur.com/blog/my-bash-history#comments</comments>
		<pubDate>Mon, 04 Aug 2008 01:31:08 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[history]]></category>

		<guid isPermaLink="false">http://craigjolicoeur.com/?p=60</guid>
		<description><![CDATA[Here is my recent bash history]]></description>
			<content:encoded><![CDATA[<pre class="brush: bash;">
$ history 1000 | \
awk '{a[$2]++}END{for(i in a){print a[i] &quot; &quot; i}}' | \
sort -rn | head

123 git
80 ruby
71 gs
43 cls
20 git-wtf
18 ll
17 rake
17 gba
16 cd
12 vim
</pre>
<p>I guess you can say I took the git plunge whole-heartedly.  The gs, gba, and git-wtf commands are all git aliases or scripts (git status, git branch -a, and a git branch commit analyzer).</p>
]]></content:encoded>
			<wfw:commentRss>http://craigjolicoeur.com/blog/my-bash-history/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hosting Git Repositories on Dreamhost</title>
		<link>http://craigjolicoeur.com/blog/hosting-git-repositories-on-dreamhost</link>
		<comments>http://craigjolicoeur.com/blog/hosting-git-repositories-on-dreamhost#comments</comments>
		<pubDate>Mon, 14 Apr 2008 14:12:46 +0000</pubDate>
		<dc:creator>Craig</dc:creator>
				<category><![CDATA[dreamhost]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://www.craigjolicoeur.com/2008/04/14/hosting-git-repositories-on-dreamhost/</guid>
		<description><![CDATA[Over the weekend I went searching for a way to host remote git repositories on my Dreamhost (DH) account. I do a fair bit of development year round and up to this point have been hosting all my code on my DH account using Subverision. Over the past few weeks I&#8217;ve been making the move [...]]]></description>
			<content:encoded><![CDATA[<p>Over the weekend I went searching for a way to host remote git repositories on my <a href="http://www.dreamhost.com/r.cgi?225041">Dreamhost</a> (DH) account.  I do a fair bit of development year round and up to this point have been <a href="http://svn.craigjolicoeur.com/">hosting all my code on my DH account using Subverision</a>.  Over the past few weeks I&#8217;ve been making the move from <a href="http://subversion.tigris.org/">Subversion</a> to <a href="http://git.or.cz/">Git</a> on my local dev machines, and figured it was time to start hosting my git repositories remotely as well.</p>
<p>It took a lot of searching around online and some tinkering, but I was able to get everything setup properly and in the hopes of saving everyone else some time, I&#8217;ll post my results here.</p>
<p>First, if you take a look at the <a href="http://wiki.dreamhost.com/Git">DH wiki entry for Git</a>, you will see the very first method described is to run Git on your DH account using <a href="http://en.wikipedia.org/wiki/Webdav">WebDAV</a>.  If you&#8217;re like me, thinking about doing Git over WebDAV probably just left you scratching your head.  I think the reason why this is advocated, is because of the way DH setups SSH accounts.  By doing git over SSH to a DH account, only one person would be able to remotely push changes, which is fine for my needs.  But, if you need to give multiple users access for pushes, then WebDAV would technically work for you.  But, I opted not to go down this route.</p>
<p>I chose to simply compile Git locally into my DH account and connect to it over SSH.  <a href="http://autopragmatic.com/2008/01/26/hosting-a-git-repository-on-dreamhost/">This blog post on Autopragmatic.com</a> got me about 90% of the way toward completion, so the next few steps are taken directly from his post.</p>
<p><b>Step 1. Compile and Install Git on Dreamhost</b></p>
<p>The first thing that needs to be done is to compile Git locally into your DH account.  I personally have a <b>~/src</b> directory where I download and compile all my code and I have a <b>~/packages</b> directory where I install my binaries.  You may have a different setup so if so, just substitute those paths accordingly.  Also, make sure to substitute $USER with your DH username. (Also note the current stable version of git might be different from what you see here.  At the time of this writing, 1.5.4.rc4 was the most recent version, but feel free to install a newer version if available.)</p>
<pre class="brush: bash;">
$ cd ~/src
$ wget http://www.kernel.org/pub/software/scm/git/git-1.5.4.rc4.tar.gz
$ tar xvzf git-1.5.4.rc4.tar.gz
$ cd git-1.5.4.rc4
$ ./configure --prefix=/home/$USER/packages NO_CURL=1 NO_MMAP=1
$ make
$ make install
$ git --version
</pre>
<p>There are a few things to be aware of.  First, the <b>NO_MMAP=1</b> parameter is necessary to keep the DH process police from killing your Git process.  Git normally creates two 250MB memory map files, and DH will kill your Git process since it sees it consuming over 500MB of memory.  I also used the <b>NO_CURL=1</b> parameter as I will not be needing my git repositories to have the ability to pull from other remote locations.  If you do need this functionality, then you will also need to download, compile and install <a href="http://curl.haxx.se/">libcurl</a>, but that is beyond the scope of this post.  Also, make sure that you have the path of your installed binaries in your <b>$PATH</b> or that last command of <b>git &#8211;version</b> will fail.  In my case, I have added <b>/home/$USER/packages/bin</b> to my <b>$PATH</b> in my <b>~/.bashrc</b> file.</p>
<p><b>Step 2.  Create a new bare Git repository</b></p>
<p>Now that you have installed git, you can start making new repositories.  You can, of course, store these repositories anywhere you want.  I chose to create a whole new sub-domain under the <a href="https://panel.dreamhost.com/index.cgi?tree=domain.manage&#038;">Dreamhost Domains Panel</a>.  Some people prefer to instead create a git subdirectory under an existing domain.  Any way is fine, the choice is yours.  For the rest of this post I&#8217;ll simply be refering to <b>git.example.com</b> as the &lt;PATH&gt; of my git repositories.  You will change this to your path.</p>
<p>If you plan on making multiple repositories, the easiest thing to do is simply automate the process by adding the following function to your <b>~/.bashrc</b> file.</p>
<pre class="brush: bash;">
newgit()
{
    if [ -z $1 ]; then
        echo &quot;usage: $FUNCNAME project-name.git&quot;
    else
        gitdir=&quot;/home/$USER/$PATH/$1&quot;
        mkdir $gitdir
        pushd $gitdir
        git --bare init
        git --bare update-server-info
        chmod a+x hooks/post-update
        touch git-daemon-export-ok
        popd
    fi
}
</pre>
<p>This way you can simply login to your DH account and type:</p>
<pre class="brush: bash; light: true;">$ newgit my-new-repos.git</pre>
<p>and a new bare repository will be created for you in your &lt;PATH&gt;. Or if you prefer to create a new repository from your local box you could even do it over SSH:</p>
<pre class="brush: bash; light: true;">$ ssh $USER@$MACHINE.dreamhost.com newgit my-new-repos.git</pre>
<p><b>Step 3. Pull and push to your new repository</b></p>
<p>Theoretically, you should now be able to pull and push from this bare repository using the following command:</p>
<pre class="brush: bash;">
$ git clone ssh://$USER@$MACHINE.dreamhost.com/home/$USER/$PATH/repo-name.git
$ git push origin
</pre>
<p>However, I found this did not work for me and resulted in the following errors:</p>
<pre class="brush: bash;">
Initialized empty Git repository in ~/src/newrepo/.git/
Bad port ”
fatal: no matching remote head
fetch-pack from ’ssh://$USER@$MACHINE.dreamhost.com:/home/$USER/$PATH/my-new-repo.git’ failed.
</pre>
<p>The problem is that the new repository is bare and has absolutely no data in it at all.  That led me on another search that brought me to <a href="http://madduck.net/blog/2007.07.11:publishing-git-repositories/">this excellent writeup</a> that got me the rest of the way home.  What I did was simply changed directories into my local git repository.  If you haven&#8217;t even started your codebase locally yet, I would recommend going ahead and doing that.</p>
<p>Create a new directory and create or add in your files, then do the following to setup a local git repos:</p>
<pre class="brush: bash;">
$ cd /my/code/path
$ git init
$ git add .
$ git commit -m &quot;initial import&quot;
</pre>
<p>That will create a local git repository in your working directory and commit the initial files. Next follow the next set of commands to add your DH repos as a remote and push your initial codebase up to it.</p>
<pre class="brush: bash;">
### assuming ssh://server/remote.git resolves to an empty, bare git repo
### and that we are chdir()'d to the local repository:
$ git push --all ssh://$USER@$MACHINE.dreamhost.com/home/$USER/$PATH/my-new-repos.git
$ git remote add origin ssh://$USER@$MACHINE.dreamhost.com/home/$USER/$PATH/my-new-repos.git
$ git config branch.master.remote origin
$ git config branch.master.merge refs/heads/master
$ git fetch
$ git merge master
$ git branch -a
* master
  origin/master
</pre>
<p>Now you can simply work locally and do a </p>
<pre class="brush: bash; light: true;">$ git push</pre>
<p>to push to your DH remote.  And if you ever need to you can simply execute a </p>
<pre class="brush: bash; light: true;">$ git pull</pre>
<p>to pull down and merge remote changes.</p>
<p><b>Step 4. Setup GitWeb (optional)</b></p>
<p>If you want to be able to access your git repositories via a web browser, you need to setup GitWeb.  GitWeb ships with the git source code so you already have it available.  You just need to copy the GitWeb files into your git repository directory and make them executable.</p>
<pre class="brush: bash;">
cd &lt;PATH&gt;;
cp ~/src/git-1.5.4.rc4/gitweb/git* .
rm gitweb.perl
chmod 755 gitweb.cgi
</pre>
<p>Its a good idea to create a configuration file as well:</p>
<pre class="brush: bash;">
touch gitweb_config.perl
vim gitweb_config.perl
</pre>
<p>and put this as the
<pre>gitweb_config.perl</pre>
<p> content:</p>
<pre class="brush: perl;">
# where is the git binary?
$GIT = &quot;/home/$USER/packages/bin/git&quot;;

# where are our git project repositories?
$projectroot = &quot;/home/$USER/git.example.com&quot;;

# what do we call our projects in the gitweb UI?
$home_link_str = &quot;My Git Projects&quot;

#  where are the files we need for gitweb to display?
@stylesheets = (&quot;gitweb.css&quot;);
$logo = &quot;git-logo.png&quot;;
$favicon = &quot;git-favicon.png&quot;;

# what do we call this site?
$site_name = &quot;My Personal Git Repositories&quot;;
</pre>
<p>Then to get it to actually run in the browser you need to tell apache to serve the files up via CGI.  Edit your
<pre>.htaccess</pre>
<p> file with the following info:</p>
<pre class="brush: plain;">
Options +ExecCGI
RewriteEngine On
RewriteRule ^$ gitweb.cgi
RewriteRule ^([?].*)$ gitweb.cgi$1
</pre>
<p>Now you should be able to access your git repositories from you web browser at http://git.example.com.</p>
<p>I personally went one step further and password protected my repositories.  If you don&#8217;t want your git repositories exposed to the whole world, you might want to do the same thing. I used simply HTTP authentication by adding the following to the bottom of my
<pre>.htaccess</pre>
<p> file:</p>
<pre class="brush: plain;">
AuthType Basic
AuthName &quot;Private Git Repository Access&quot;
AuthUserFile /home/$USER/.htpasswd
Require valid-user
</pre>
<p>This, of course, requires that you have proper
<pre>.htpasswd</pre>
<p> file setup which is beyond the scope of this tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://craigjolicoeur.com/blog/hosting-git-repositories-on-dreamhost/feed</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
	</channel>
</rss>

