<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss 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/" version="2.0">

<channel>
	<title>Kleinsch » How-To</title>
	
	<link>http://www.kleinsch.com</link>
	<description>Nick Kleinschmidt's Blog</description>
	<lastBuildDate>Sun, 05 Feb 2012 23:10:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.4</generator>
		<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/rss+xml" href="http://feeds.feedburner.com/kleinsch/howto" /><feedburner:info xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" uri="kleinsch/howto" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><item>
		<title>Git Workflow – Part 4: Remote Branches</title>
		<link>http://www.kleinsch.com/2009/10/03/git-workflow-%e2%80%93-part-4-remote-branches/</link>
		<comments>http://www.kleinsch.com/2009/10/03/git-workflow-%e2%80%93-part-4-remote-branches/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 15:35:51 +0000</pubDate>
		<dc:creator>Nick Kleinschmidt</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://kleinsch.com/?p=136</guid>
		<description><![CDATA[The final piece of Git I'll be covering is using shared remote branches. This can be helpful if you have a team working on a development and a release branch, among other scenarios.]]></description>
			<content:encoded><![CDATA[<p>The final piece of Git I&#8217;ll be covering is using shared remote branches. This can be helpful if you have a team working on a development and a release branch, among other scenarios.</p>
<p>I&#8217;ll start by setting up a central repository and two working repositories based off it. I&#8217;ll be supplying an extra argument to the clone command to make things less confusing, this gives the name of the directory in which to check out the branch. For example, &#8220;git checkout first.git&#8221; (no argument) checks out into a directory called &#8220;first&#8221;. Using &#8220;git checkout first.git second&#8221; will check out into a directory called &#8220;second&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:tmp nick$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> first.git <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">cd</span> first.git
Kleinschs-Macbook:first.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> <span style="color: #660033;">--bare</span> init <span style="color: #660033;">--shared</span>
Initialized empty shared Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first.git<span style="color: #000000; font-weight: bold;">/</span>
Kleinschs-Macbook:first.git nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..
Kleinschs-Macbook:tmp nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> clone first.git second
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>second<span style="color: #000000; font-weight: bold;">/</span>.git<span style="color: #000000; font-weight: bold;">/</span>
warning: You appear to have cloned an empty repository.
Kleinschs-Macbook:tmp nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> second
Kleinschs-Macbook:second nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'First file contents'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file1
Kleinschs-Macbook:second nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> add file1
Kleinschs-Macbook:second nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'added first file'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>master <span style="color: #7a0874; font-weight: bold;">&#40;</span>root-commit<span style="color: #7a0874; font-weight: bold;">&#41;</span> 19b39e3<span style="color: #7a0874; font-weight: bold;">&#93;</span> added first <span style="color: #c20cb9; font-weight: bold;">file</span>
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> file1
Kleinschs-Macbook:second nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> push origin master
Counting objects: <span style="color: #000000;">3</span>, done.
Writing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">243</span> bytes, done.
Total <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Unpacking objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
To <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first.git
 <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>new branch<span style="color: #7a0874; font-weight: bold;">&#93;</span>      master -<span style="color: #000000; font-weight: bold;">&gt;</span> master
Kleinschs-Macbook:second nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..
Kleinschs-Macbook:tmp nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> clone first.git third
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>third<span style="color: #000000; font-weight: bold;">/</span>.git<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Now that I have two working repositories, I&#8217;ll go create a release branch on the second repository.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:tmp nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> second
Kleinschs-Macbook:second nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">-b</span> release
Switched to a new branch <span style="color: #ff0000;">'release'</span>
Kleinschs-Macbook:second nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'Second file contents'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file2
Kleinschs-Macbook:second nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> add file2
Kleinschs-Macbook:second nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'added file2'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>release 48a00ee<span style="color: #7a0874; font-weight: bold;">&#93;</span> added file2
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> file2</pre></div></div>

<p>Since I have this release branch, I&#8217;d like to expose it to the rest of the team so that everyone is looking at the same version. Adding a branch is as simple as doing a push with the name of the new branch. In this example, I&#8217;m telling Git to push to a remote branch that doesn&#8217;t exist, so it creates it.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:second nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> push origin release:release
Counting objects: <span style="color: #000000;">4</span>, done.
Delta compression using up to <span style="color: #000000;">2</span> threads.
Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
Writing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">292</span> bytes, done.
Total <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Unpacking objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
To <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first.git
 <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>new branch<span style="color: #7a0874; font-weight: bold;">&#93;</span>      release -<span style="color: #000000; font-weight: bold;">&gt;</span> release</pre></div></div>

<p>Listing the branches will show that the branch was created on the remote repository as well.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:second nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch <span style="color: #660033;">-a</span>
  master
<span style="color: #000000; font-weight: bold;">*</span> release
  remotes<span style="color: #000000; font-weight: bold;">/</span>origin<span style="color: #000000; font-weight: bold;">/</span>master
  remotes<span style="color: #000000; font-weight: bold;">/</span>origin<span style="color: #000000; font-weight: bold;">/</span>release</pre></div></div>

<p>Now let&#8217;s go over to the third repository and make sure we can access the release branch. First we do a pull to make sure we have the latest data from the remote server.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:second nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>third<span style="color: #000000; font-weight: bold;">/</span>
Kleinschs-Macbook:third nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> pull
remote: Counting objects: <span style="color: #000000;">4</span>, done.
remote: Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
remote: Total <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Unpacking objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
From <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first
 <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>new branch<span style="color: #7a0874; font-weight: bold;">&#93;</span>      release    -<span style="color: #000000; font-weight: bold;">&gt;</span> origin<span style="color: #000000; font-weight: bold;">/</span>release
Already up-to-date.
Kleinschs-Macbook:third nick$ <span style="color: #c20cb9; font-weight: bold;">ls</span>
file1</pre></div></div>

<p>We&#8217;re still not seeing the second file that was checked in on the release branch. This is because we&#8217;re still on the master branch at this point. In order to access the remote release branch, we need to create a local tracking branch for our changes. A tracking branch is a local branch that&#8217;s set up with a remote branch so that pushes and pulls go to the corresponding remote branch. In order to set up a tracking branch, just supply the &#8220;&#8211;track&#8221; flag to the branch command.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:third nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch <span style="color: #660033;">--track</span> release origin<span style="color: #000000; font-weight: bold;">/</span>release
Branch release <span style="color: #000000; font-weight: bold;">set</span> up to track remote branch release from origin.
Kleinschs-Macbook:third nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout release
Switched to branch <span style="color: #ff0000;">'release'</span>
Kleinschs-Macbook:third nick$ <span style="color: #c20cb9; font-weight: bold;">ls</span>
file1	file2</pre></div></div>

<p>As you can see, we received the second file that was checked in on the release branch, so we should be ready to go. There&#8217;s one more thing I&#8217;d like to clear up. What if you have an existing branch that you&#8217;d like to have track a remote branch? The easiest way to do this is to edit your Git config file. Outputting the config from the the third repository will make this a little more clear.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:third nick$ <span style="color: #c20cb9; font-weight: bold;">cat</span> .git<span style="color: #000000; font-weight: bold;">/</span>config
<span style="color: #7a0874; font-weight: bold;">&#91;</span>core<span style="color: #7a0874; font-weight: bold;">&#93;</span>
	repositoryformatversion = <span style="color: #000000;">0</span>
	filemode = <span style="color: #c20cb9; font-weight: bold;">true</span>
	bare = <span style="color: #c20cb9; font-weight: bold;">false</span>
	logallrefupdates = <span style="color: #c20cb9; font-weight: bold;">true</span>
	ignorecase = <span style="color: #c20cb9; font-weight: bold;">true</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>remote <span style="color: #ff0000;">&quot;origin&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
	fetch = +refs<span style="color: #000000; font-weight: bold;">/</span>heads<span style="color: #000000; font-weight: bold;">/*</span>:refs<span style="color: #000000; font-weight: bold;">/</span>remotes<span style="color: #000000; font-weight: bold;">/</span>origin<span style="color: #000000; font-weight: bold;">/*</span>
	url = <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first.git
<span style="color: #7a0874; font-weight: bold;">&#91;</span>branch <span style="color: #ff0000;">&quot;master&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
	remote = origin
	merge = refs<span style="color: #000000; font-weight: bold;">/</span>heads<span style="color: #000000; font-weight: bold;">/</span>master
<span style="color: #7a0874; font-weight: bold;">&#91;</span>branch <span style="color: #ff0000;">&quot;release&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
	remote = origin
	merge = refs<span style="color: #000000; font-weight: bold;">/</span>heads<span style="color: #000000; font-weight: bold;">/</span>release</pre></div></div>

<p>The section for branch &#8220;release&#8221; has the relevant information. If you wanted to set up the second repository so its release branch was tracking the remote release branch, you just need to add these three lines to second/.git/config.</p>
<p>This concludes my series on Git. There&#8217;s a lot more to it than these four articles describe, but this should be a good jumping off point.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kleinsch.com/2009/10/03/git-workflow-%e2%80%93-part-4-remote-branches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git Workflow – Part 3: Remote Operations</title>
		<link>http://www.kleinsch.com/2009/09/30/git-workflow-part-3-remote-operations/</link>
		<comments>http://www.kleinsch.com/2009/09/30/git-workflow-part-3-remote-operations/#comments</comments>
		<pubDate>Wed, 30 Sep 2009 12:16:01 +0000</pubDate>
		<dc:creator>Nick Kleinschmidt</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://kleinsch.com/?p=115</guid>
		<description><![CDATA[Using Git on a single machine may have its uses, but most people using Git are using it for its remote operations. Git functions in a variety of ways, I'll be focusing on a central repository in this article. For more complicated workflows, see the <a href="http://book.git-scm.com/">Git Book</a>.

The first thing to do is to set up a central repository.]]></description>
			<content:encoded><![CDATA[<p>Using Git on a single machine may have its uses, but most people using Git are using it for its remote operations. Git functions in a variety of ways, I&#8217;ll be focusing on a central repository in this article. For more complicated workflows, see the <a href="http://book.git-scm.com/">Git Book</a>.</p>
<p>The first thing to do is to set up a central repository. You can make it a normal Git repository like any other, but a few things will be easier if you make it what&#8217;s called a bare repository. This means that there&#8217;s no working copy, it just stores revisions. Adding the flag &#8220;&#8211;bare&#8221; to the init command sets it up as bare. I also like to add the &#8220;&#8211;shared&#8221; flag if you&#8217;re going to be sharing it across multiple users, this helps fix permissions. Look it up if you&#8217;re very curious. It also helps to name the shared repository ending in &#8220;.git&#8221;. If it&#8217;s set up that way, when people clone it, Git will lose the extension and just take the name. We&#8217;ll see that below.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:tmp nick$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> first.git <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">cd</span> first.git
Kleinschs-Macbook:first.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> <span style="color: #660033;">--bare</span> init <span style="color: #660033;">--shared</span>
Initialized empty shared Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first.git<span style="color: #000000; font-weight: bold;">/</span></pre></div></div>

<p>Now that the bare repository is set up, we need to get something into it. There are two ways to connect to a remote repository: cloning and adding to an existing repository. I&#8217;ll add it to an existing repository first. This can be handy if you want to import existing files into a new repository.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first.git nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..
Kleinschs-Macbook:tmp nick$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> second.git <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">cd</span> second.git
Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> init
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>second.git<span style="color: #000000; font-weight: bold;">/</span>.git<span style="color: #000000; font-weight: bold;">/</span>
Kleinschs-Macbook:second.git nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'First file contents'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file1
Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> add file1
Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'Added file1'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>master <span style="color: #7a0874; font-weight: bold;">&#40;</span>root-commit<span style="color: #7a0874; font-weight: bold;">&#41;</span> 1a603a8<span style="color: #7a0874; font-weight: bold;">&#93;</span> Added file1
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> file1</pre></div></div>

<p>Up to this point everything is standard. In order to commit changes into the central repository, we need to add the server and push the changes. The &#8220;remote&#8221; command takes care of remote repository setup in Git. The &#8220;remote add&#8221; adds a remote location, with the first parameter being the name and second being the location. In this example I&#8217;m using a local repository, but you could also do it via SSH, which I&#8217;ll show later. After you&#8217;ve added the remote location, use the &#8220;push&#8221; command to commit your changes to the remote branch. The first parameter is the remote location (using the name you just specified in the &#8220;remote add&#8221; command), second parameter is the remote branch for the commit. This pushes your current branch to the specified remote branch. For example, if I give the command &#8220;git push origin master&#8221;, it pushes my current branch to the master branch of the remote repository named origin. If you don&#8217;t want to push your current branch, you can specify which local branch to push in the command like this: &#8220;git push origin local-branch:remote-branch&#8221;. This would commit my branch named local-branch to the branch named remote-branch on origin.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> remote add origin ..<span style="color: #000000; font-weight: bold;">/</span>first.git
Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> push origin master
Counting objects: <span style="color: #000000;">3</span>, done.
Writing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">239</span> bytes, done.
Total <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Unpacking objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
To ..<span style="color: #000000; font-weight: bold;">/</span>first.git
 <span style="color: #000000; font-weight: bold;">*</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>new branch<span style="color: #7a0874; font-weight: bold;">&#93;</span>      master -<span style="color: #000000; font-weight: bold;">&gt;</span> master</pre></div></div>

<p>Now that we&#8217;ve got an initial commit in, let&#8217;s try the second way of connecting to a remote repository. The command &#8220;clone&#8221; copies everything from an existing repository and sets it up as a new repository. Again, in this example I&#8217;m using a local directory as the argument, but it can take other arguments including SSH.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:second.git nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..
Kleinschs-Macbook:tmp nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> clone first.git
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first<span style="color: #000000; font-weight: bold;">/</span>.git<span style="color: #000000; font-weight: bold;">/</span>
Kleinschs-Macbook:tmp nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> first
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">ls</span>
file1</pre></div></div>

<p>Notice that we cloned &#8220;first.git&#8221;, so our clone is just named &#8220;first&#8221;. Let&#8217;s try adding a file through the newly cloned branch.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'Second file contents'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file2
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> add file2
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'added second file'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>master 478a452<span style="color: #7a0874; font-weight: bold;">&#93;</span> added second <span style="color: #c20cb9; font-weight: bold;">file</span>
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> file2
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> status
<span style="color: #666666; font-style: italic;"># On branch master</span>
<span style="color: #666666; font-style: italic;"># Your branch is ahead of 'origin/master' by 1 commit.</span>
<span style="color: #666666; font-style: italic;">#</span>
nothing to commit <span style="color: #7a0874; font-weight: bold;">&#40;</span>working directory clean<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>If you compared the .git/config files between second.git and first (the cloned repository), you&#8217;ll notice that in the cloned repository, there&#8217;s an extra line about our master branch:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>branch <span style="color: #ff0000;">&quot;master&quot;</span><span style="color: #7a0874; font-weight: bold;">&#93;</span>
	remote = origin
	merge = refs<span style="color: #000000; font-weight: bold;">/</span>heads<span style="color: #000000; font-weight: bold;">/</span>master</pre></div></div>

<p>This sets up our local branch to link to origin&#8217;s master branch. This means that when we do remote operations from our master branch, we don&#8217;t have to specify the remote location or branch. This means that in order to push our changes, we just have to do a &#8220;git push&#8221;.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> push
Counting objects: <span style="color: #000000;">4</span>, done.
Delta compression using up to <span style="color: #000000;">2</span> threads.
Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
Writing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">300</span> bytes, done.
Total <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Unpacking objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
To <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first.git
   1a603a8..478a452  master -<span style="color: #000000; font-weight: bold;">&gt;</span> master</pre></div></div>

<p>Now that we&#8217;re pushing changes out frequently, we need to be able to download those changes from the central repository. The &#8220;fetch&#8221; command gets all revisions from a remote repository.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>second.git
Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> fetch origin
remote: Counting objects: <span style="color: #000000;">4</span>, done.
remote: Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
remote: Total <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Unpacking objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
From ..<span style="color: #000000; font-weight: bold;">/</span>first
   1a603a8..478a452  master     -<span style="color: #000000; font-weight: bold;">&gt;</span> origin<span style="color: #000000; font-weight: bold;">/</span>master</pre></div></div>

<p>You&#8217;ll see it downloaded them and refers to them using the notation &#8220;remote-location/remote-branch-name&#8221;. The fetch command doesn&#8217;t move the changes into your existing working copy, you&#8217;ll need to take care of this yourself. In order to pull the changes into your current local branch, you do a normal merge.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> merge origin<span style="color: #000000; font-weight: bold;">/</span>master
Updating 1a603a8..478a452
Fast forward
 file2 <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">1</span> +
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> file2</pre></div></div>

<p>Since the process of fetching and merging is a frequent one, there&#8217;s a command that combines them: &#8220;pull&#8221;. Doing a pull runs a fetch and merges the specified remote branch into your current local one.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> pull origin master
From ..<span style="color: #000000; font-weight: bold;">/</span>first
 <span style="color: #000000; font-weight: bold;">*</span> branch            master     -<span style="color: #000000; font-weight: bold;">&gt;</span> FETCH_HEAD
Already up-to-date.</pre></div></div>

<p>Pulling and pushing is fairly simple, but there&#8217;s one common error I&#8217;ve run into that I&#8217;ll illustrate here. I&#8217;m going to push a commit from my second repository, then try to push a commit from my cloned repository.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:second.git nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'Third file contents'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file3
Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> add file3
Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'added third file'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>master c114c2b<span style="color: #7a0874; font-weight: bold;">&#93;</span> added third <span style="color: #c20cb9; font-weight: bold;">file</span>
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> file3
Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> push
Counting objects: <span style="color: #000000;">4</span>, done.
Delta compression using up to <span style="color: #000000;">2</span> threads.
Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
Writing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">324</span> bytes, done.
Total <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Unpacking objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
To ..<span style="color: #000000; font-weight: bold;">/</span>first.git
   478a452..c114c2b  master -<span style="color: #000000; font-weight: bold;">&gt;</span> master
&nbsp;
Kleinschs-Macbook:second.git nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>first
Kleinschs-Macbook:first nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'Fourth file contents'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file4
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> add file4
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'added fourth file'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>master 17411ef<span style="color: #7a0874; font-weight: bold;">&#93;</span> added fourth <span style="color: #c20cb9; font-weight: bold;">file</span>
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> file4
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> push
To <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first.git
 <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span>rejected<span style="color: #7a0874; font-weight: bold;">&#93;</span>        master -<span style="color: #000000; font-weight: bold;">&gt;</span> master <span style="color: #7a0874; font-weight: bold;">&#40;</span>non-fast forward<span style="color: #7a0874; font-weight: bold;">&#41;</span>
error: failed to push some refs to <span style="color: #ff0000;">'/Users/nick/tmp/first.git'</span>
To prevent you from losing <span style="color: #7a0874; font-weight: bold;">history</span>, non-fast-forward updates were rejected.
Merge the remote changes before pushing again.
See <span style="color: #ff0000;">'non-fast forward'</span> section of <span style="color: #ff0000;">'git push --help'</span> <span style="color: #000000; font-weight: bold;">for</span> details.</pre></div></div>

<p>When I tried to do the second push, it was rejected. This is because Git requires that push operations result in a fast forward merge. If push operations didn&#8217;t have to be fast forward there could be unresolvable conflicts on the central server, which would leave things in a bad state for other users. For this reason, you need to take care of conflicts locally before doing a push. The simple fix for this is to do a pull and make sure you&#8217;re up to date before trying to do a push. If your changes really have to go in, there are ways to override the fast forward requirement, see the Git book for advanced options.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> pull
remote: Counting objects: <span style="color: #000000;">4</span>, done.
remote: Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
remote: Total <span style="color: #000000;">3</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Unpacking objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">3</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">3</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
From <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first
   478a452..c114c2b  master     -<span style="color: #000000; font-weight: bold;">&gt;</span> origin<span style="color: #000000; font-weight: bold;">/</span>master
Merge made by recursive.
 file3 <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">1</span> +
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> file3
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> push
Counting objects: <span style="color: #000000;">7</span>, done.
Delta compression using up to <span style="color: #000000;">2</span> threads.
Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
Writing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">533</span> bytes, done.
Total <span style="color: #000000;">5</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Unpacking objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
To <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>first.git
   c114c2b..<span style="color: #000000;">5890924</span>  master -<span style="color: #000000; font-weight: bold;">&gt;</span> master</pre></div></div>

<p>Now let&#8217;s go back over to the second repository to make sure our changes went through correctly.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #7a0874; font-weight: bold;">cd</span> ..<span style="color: #000000; font-weight: bold;">/</span>second.git
Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> pull origin master
remote: Counting objects: <span style="color: #000000;">7</span>, done.
remote: Compressing objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">4</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">4</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
remote: Total <span style="color: #000000;">5</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">2</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, reused <span style="color: #000000;">0</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span>delta <span style="color: #000000;">0</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
Unpacking objects: <span style="color: #000000;">100</span><span style="color: #000000; font-weight: bold;">%</span> <span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #000000;">5</span><span style="color: #000000; font-weight: bold;">/</span><span style="color: #000000;">5</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>, done.
From ..<span style="color: #000000; font-weight: bold;">/</span>first
 <span style="color: #000000; font-weight: bold;">*</span> branch            master     -<span style="color: #000000; font-weight: bold;">&gt;</span> FETCH_HEAD
Updating c114c2b..<span style="color: #000000;">5890924</span>
Fast forward
 file4 <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">1</span> +
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
 create mode <span style="color: #000000;">100644</span> file4
Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">ls</span>
file1	file2	file3	file4</pre></div></div>

<p>Everything looks good! I spoke above about setting up repositories over SSH. You&#8217;ll need to have a valid account on the machine to connect to a Git repository. It&#8217;s usually helpful to set up a public/private key so you don&#8217;t have to specify the password every time. There are other way to connect, but they&#8217;re a bit more involved. Google and the Git Book are your friend here (start by looking up Gitosis). Here&#8217;s an example of the connect string to use with SSH.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>nick<span style="color: #000000; font-weight: bold;">@</span>kleinsch.com<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>git<span style="color: #000000; font-weight: bold;">/</span>kleinsch.com.git<span style="color: #000000; font-weight: bold;">/</span>
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>second.git<span style="color: #000000; font-weight: bold;">/</span>kleinsch.com<span style="color: #000000; font-weight: bold;">/</span>.git<span style="color: #000000; font-weight: bold;">/</span>
remote: Counting objects: <span style="color: #000000;">2181</span>, done.
...</pre></div></div>

<p>I&#8217;ve made one mistake with SSH connect strings a couple of times now: this is <em>not</em> the same as the connect string for SCP. There&#8217;s no colon between the server and the path, unless you&#8217;re specifying a port. If you put one, you&#8217;ll just get a confusing error message, shown below.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:second.git nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> clone <span style="color: #c20cb9; font-weight: bold;">ssh</span>:<span style="color: #000000; font-weight: bold;">//</span>nick<span style="color: #000000; font-weight: bold;">@</span>kleinsch.com:<span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>git<span style="color: #000000; font-weight: bold;">/</span>kleinsch.com.git<span style="color: #000000; font-weight: bold;">/</span>
Initialized empty Git repository <span style="color: #000000; font-weight: bold;">in</span> <span style="color: #000000; font-weight: bold;">/</span>Users<span style="color: #000000; font-weight: bold;">/</span>nick<span style="color: #000000; font-weight: bold;">/</span>tmp<span style="color: #000000; font-weight: bold;">/</span>second.git<span style="color: #000000; font-weight: bold;">/</span>kleinsch.com<span style="color: #000000; font-weight: bold;">/</span>.git<span style="color: #000000; font-weight: bold;">/</span>
<span style="color: #c20cb9; font-weight: bold;">ssh</span>: Could not resolve <span style="color: #c20cb9; font-weight: bold;">hostname</span> kleinsch.com:: nodename nor servname provided, or not known
fatal: The remote end hung up unexpectedly</pre></div></div>

<p>That covers the basics of remote operations. I&#8217;ll be doing one more post about Git focusing on remote branches.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kleinsch.com/2009/09/30/git-workflow-part-3-remote-operations/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Git Workflow – Part 2: Branches</title>
		<link>http://www.kleinsch.com/2009/08/26/git-workflow-part-2-branches/</link>
		<comments>http://www.kleinsch.com/2009/08/26/git-workflow-part-2-branches/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 23:28:31 +0000</pubDate>
		<dc:creator>Nick Kleinschmidt</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://kleinsch.com/?p=59</guid>
		<description><![CDATA[The command 'branch' with no arguments will tell you which branches exist and put an asterisk next to the branch on which you're currently working. If you pass in a name, Git will create a branch with that name.]]></description>
			<content:encoded><![CDATA[<p>In the first tutorial, I showed how to set up a Git repository and commit basic changes. You could get a lot done using only those commands, but you&#8217;d be missing out on most of the benefits of Git. Most of that could be done in SVN or CVS fairly easily. In this tutorial, I&#8217;ll go through setting up branches and merging changes, one of Git&#8217;s main strengths. Git was built from the ground up for frequent branching. In other version control systems, you may use branches for releases or major events, but in Git your day to day workflow revolves around branches.</p>
<p>If you don&#8217;t want to go back through the first post, the following commands will get you in sync with what I set up in the first post.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">mkdir</span> first <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">cd</span> first
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'firstEdit'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file1
<span style="color: #c20cb9; font-weight: bold;">git</span> init
<span style="color: #c20cb9; font-weight: bold;">git</span> add file1
<span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-m</span><span style="color: #ff0000;">'First commit'</span>
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'secondEdit'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file1
<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'anotherFile'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file2
<span style="color: #c20cb9; font-weight: bold;">git</span> add file2
<span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'Made a second commit!'</span></pre></div></div>

<p>Branches have been a useful tool in version control for quite some time. They allow multiple versions of the same project to be actively developed. One of the most common use cases for branches is bug fixing. Let&#8217;s say you have a project that&#8217;s been released and you&#8217;re working on new features. Maybe you&#8217;ve committed a bunch of files but they&#8217;re not ready to go out to production. A user finds a showstopping bug that needs to be fixed immediately. Some people would pull the code from the production release, hack together a patch, and push it out. With branches, you can get the production branch, fix the bug, check in the changes, then switch back to your development branch and merge the changes. This tracks your changes so if you have to fix another production bug, nobody has to remember what went out in the last patch.</p>
<p>The command &#8216;branch&#8217; with no arguments will tell you which branches exist and put an asterisk next to the branch on which you&#8217;re currently working. If you pass in a name, Git will create a branch with that name.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch
<span style="color: #000000; font-weight: bold;">*</span> master
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch development
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch
  development
<span style="color: #000000; font-weight: bold;">*</span> master</pre></div></div>

<p>The &#8216;checkout&#8217; command switches to another branch. One shortcut you can take is the &#8216;-b&#8217; flag to &#8216;checkout&#8217; which creates the branch and checks it out.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout development
Switched to branch <span style="color: #ff0000;">'development'</span>
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch
<span style="color: #000000; font-weight: bold;">*</span> development
  master
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">-b</span> my-dev-branch
Switched to a new branch <span style="color: #ff0000;">'my-dev-branch'</span>
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch
  development
  master
<span style="color: #000000; font-weight: bold;">*</span> my-dev-branch</pre></div></div>

<p>The command &#8216;gitk&#8217; brings up a window that shows the state of your branches graphically. By default, it hides branches not related to the current branch. The flag &#8216;&#8211;all&#8217; is useful to show all branches. This is useful in figuring out complicated branching and merging scenarios. The most useful part of the display is the top left corner, which shows your branches in order of commits. More recent commits are at the top. Doing this on my project brings up this.</p>
<p><img src="http://kleinsch.com/wp-content/uploads/2009/08/Branch-Merge-1.png" alt="Branch-Merge-1" title="Branch-Merge-1" width="355" height="39" class="alignnone size-full wp-image-78" /></p>
<p>All of our changes are in the same place, so the branches show up on the same commit. Let&#8217;s make some changes.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">'secondEdit\n\nadded a line'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file1</pre></div></div>

<p>At this point if you change branches, your uncommitted changes will follow. Each modified file will show up with an &#8216;M&#8217; next to it when you issue the checkout command.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout development
M	file1
Switched to branch <span style="color: #ff0000;">'development'</span>
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">cat</span> file1
secondEdit
&nbsp;
added a line</pre></div></div>

<p>This seems a little strange, but can actually come in handy. Let&#8217;s say you&#8217;re working on something and it turns into a bigger project than you thought. You may want to work on that on a branch instead. In that case you can checkout onto a new branch, commit your changes, and keep working.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">-b</span> testing-theory
M	file1
Switched to a new branch <span style="color: #ff0000;">'testing-theory'</span>
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'first commit while testing something'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>testing-theory 42a287a<span style="color: #7a0874; font-weight: bold;">&#93;</span> first commit <span style="color: #000000; font-weight: bold;">while</span> testing something
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">2</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Kleinschs-Macbook:first nick$ gitk</pre></div></div>

<p><img src="http://kleinsch.com/wp-content/uploads/2009/08/Branch-Merge-2.png" alt="Branch-Merge-2" title="Branch-Merge-2" width="353" height="49" class="alignnone size-full wp-image-79" /></p>
<p>This allows you to take advantage of version control for the things you&#8217;re working on that aren&#8217;t ready to be shared with other team members. You can work on this test branch as long as you want. Let&#8217;s say at the same time, you have to fix a bug on the production release, which for this project will be the master branch. First, checkout the master branch.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout master
Switched to branch <span style="color: #ff0000;">'master'</span></pre></div></div>

<p>Let&#8217;s first create a branch for fixing this bug. It&#8217;s quick and easy, and we can track our changes. Then we can make whatever changes are necessary.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">-b</span> fixing-bug
Switched to a new branch <span style="color: #ff0000;">'fixing-bug'</span>
Kleinschs-Macbook:first nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'secondEdit - add to first line'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file1
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'fixed a bug in file1'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>fixing-bug 645e620<span style="color: #7a0874; font-weight: bold;">&#93;</span> fixed a bug <span style="color: #000000; font-weight: bold;">in</span> file1
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">1</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Kleinschs-Macbook:first nick$ gitk <span style="color: #660033;">--all</span></pre></div></div>

<p><img src="http://kleinsch.com/wp-content/uploads/2009/08/Branch-Merge-3.png" alt="Branch-Merge-3" title="Branch-Merge-3" width="352" height="56" class="alignnone size-full wp-image-80" /></p>
<p>Now that we&#8217;ve fixed the bug, we&#8217;ll roll it out to production. Let&#8217;s merge the bug fix into the master branch. For this, we use the command &#8216;merge&#8217;. You must checkout the branch you&#8217;re merging to, then supply the branch you&#8217;re merging from as the argument to the merge command.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout master
Switched to branch <span style="color: #ff0000;">'master'</span>
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> merge fixing-bug
Updating 941bde0..645e620
Fast forward
 file1 <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">2</span> +-
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">1</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Kleinschs-Macbook:first nick$ gitk <span style="color: #660033;">--all</span></pre></div></div>

<p><img src="http://kleinsch.com/wp-content/uploads/2009/08/Branch-Merge-4.png" alt="Branch-Merge-4" title="Branch-Merge-4" width="306" height="64" class="alignnone size-full wp-image-81" /></p>
<p>As you can see, we merged the changes into our master branch. This was actually a special type of merge: the fast forward merge. If the other branch already has all the commits from the current branch, Git will just add the commits from the other branch and point both branches at the same place. It&#8217;s like git is treating the commits from the fixing-bug branch as commits on the master branch.</p>
<p>Now let&#8217;s merge the changes from our testing-theory branch. This will conflict with the bug fix we just checked in, since both commits add to the first line. Usually Git is good at automatically merging, so changing two separate pieces of code in the same file won&#8217;t result in a conflict. In this example, we&#8217;ll have to resolve it. If conflicts are found, Git will leave markers in the conflicting files. After you fix the conflicts, you can run a commit to complete the merge.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> merge testing-theory
Auto-merging file1
CONFLICT <span style="color: #7a0874; font-weight: bold;">&#40;</span>content<span style="color: #7a0874; font-weight: bold;">&#41;</span>: Merge conflict <span style="color: #000000; font-weight: bold;">in</span> file1
Automatic merge failed; fix conflicts and <span style="color: #000000; font-weight: bold;">then</span> commit the result. 
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">cat</span> file1
<span style="color: #000000; font-weight: bold;">&lt;&lt;&lt;&lt;&lt;&lt;&lt;</span> HEAD:file1
secondEdit - add to first line
=======
secondEdit
&nbsp;
added a line
<span style="color: #000000; font-weight: bold;">&gt;&gt;&gt;&gt;&gt;&gt;&gt;</span> testing-theory:file1</pre></div></div>

<p>The first section shows the changes from master, the second shows the changes from testing-theory. Let&#8217;s keep both changes. I&#8217;m going to keep the first line from master and the last line from testing-theory.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">vi</span> file1 
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">cat</span> file1 
secondEdit - add to first line
&nbsp;
added a line
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> status
file1: needs merge
<span style="color: #666666; font-style: italic;"># On branch master</span>
<span style="color: #666666; font-style: italic;"># Changed but not updated:</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git add &lt;file&gt;...&quot; to update what will be committed)</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git checkout -- &lt;file&gt;...&quot; to discard changes in working directory)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#	unmerged:   file1</span>
<span style="color: #666666; font-style: italic;">#</span>
no changes added to commit <span style="color: #7a0874; font-weight: bold;">&#40;</span>use <span style="color: #ff0000;">&quot;git add&quot;</span> and<span style="color: #000000; font-weight: bold;">/</span>or <span style="color: #ff0000;">&quot;git commit -a&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Now we&#8217;re ready to finish the merge. You commit this the same as a regular commit. Since testing-theory doesn&#8217;t have the bug fix that we used to patch master, this will not be a fast forward merge.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'Merged changes from testing-theory branch'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>master d6132fa<span style="color: #7a0874; font-weight: bold;">&#93;</span> Merged changes from testing-theory branch
Kleinschs-Macbook:first nick$ gitk <span style="color: #660033;">--all</span></pre></div></div>

<p><img src="http://kleinsch.com/wp-content/uploads/2009/08/Branch-Merge-5.png" alt="Branch-Merge-5" title="Branch-Merge-5" width="320" height="77" class="alignnone size-full wp-image-82" /></p>
<p>The picture here gets a little complicated, but it shows that our master branch now incorporates changes from both the fixing-bug and testing-theory branches.</p>
<p>The complicated stuff is over! Just two more bits to clear up. Let&#8217;s create a branch and make some changes.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout <span style="color: #660033;">-b</span> another-branch
Switched to a new branch <span style="color: #ff0000;">'another-branch'</span>
Kleinschs-Macbook:first nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'bad-change'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file2</pre></div></div>

<p>If you don&#8217;t like the change and want to get rid of it, you can use the checkout command to get rid of it. SVN users: the &#8216;revert&#8217; command in Git is <em>not</em> the same as the revert command in SVN! If you&#8217;re thinking of reverting changes made to a file, make sure to use the checkout command.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout file2
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">cat</span> file2
anotherFile
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> status
<span style="color: #666666; font-style: italic;"># On branch another-branch</span>
nothing to commit <span style="color: #7a0874; font-weight: bold;">&#40;</span>working directory clean<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Let&#8217;s say it turns out you didn&#8217;t need this branch, let&#8217;s get rid of it. You first need to switch away from this branch. Then use the &#8216;-d&#8217; option to the branch command to delete unnecessary branches.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout master
Switched to branch <span style="color: #ff0000;">'master'</span>
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch <span style="color: #660033;">-d</span> another-branch
Deleted branch another-branch <span style="color: #7a0874; font-weight: bold;">&#40;</span>was d6132fa<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch
  development
  fixing-bug
<span style="color: #000000; font-weight: bold;">*</span> master
  my-dev-branch
  testing-theory</pre></div></div>

<p>You can even delete the branches you&#8217;ve committed. This won&#8217;t mess up your branching history, it just removes the branch label from those commits.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch <span style="color: #660033;">-d</span> fixing-bug
Deleted branch fixing-bug <span style="color: #7a0874; font-weight: bold;">&#40;</span>was 645e620<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch <span style="color: #660033;">-d</span> testing-theory
Deleted branch testing-theory <span style="color: #7a0874; font-weight: bold;">&#40;</span>was 42a287a<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> branch <span style="color: #660033;">-d</span> my-dev-branch
Deleted branch my-dev-branch <span style="color: #7a0874; font-weight: bold;">&#40;</span>was 5bd6207<span style="color: #7a0874; font-weight: bold;">&#41;</span>.
Kleinschs-Macbook:first nick$ gitk <span style="color: #660033;">--all</span></pre></div></div>

<p><img src="http://kleinsch.com/wp-content/uploads/2009/08/Branch-Merge-6.png" alt="Branch-Merge-6" title="Branch-Merge-6" width="318" height="67" class="alignnone size-full wp-image-83" /></p>
<p>This still shows the same history, we&#8217;ve just removed the named branches not in use. Finally, if you&#8217;re doing development, you may need to incorporate the changes that have gone into the master branch so you can start at the same point as your release.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> checkout development
Switched to branch <span style="color: #ff0000;">'development'</span>
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> merge master
Updating 941bde0..d6132fa
Fast forward
 file1 <span style="color: #000000; font-weight: bold;">|</span>    <span style="color: #000000;">4</span> +++-
 <span style="color: #000000;">1</span> files changed, <span style="color: #000000;">3</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">1</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
Kleinschs-Macbook:first nick$ gitk <span style="color: #660033;">--all</span></pre></div></div>

<p><img src="http://kleinsch.com/wp-content/uploads/2009/08/Branch-Merge-7.png" alt="Branch-Merge-7" title="Branch-Merge-7" width="362" height="65" class="alignnone size-full wp-image-84" /></p>
<p>That&#8217;s about it for branching and merging. At this point the only thing the only major thing left is setting up remote operations. I&#8217;ll cover that in the next part of this tutorial.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kleinsch.com/2009/08/26/git-workflow-part-2-branches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A Simple Git Workflow</title>
		<link>http://www.kleinsch.com/2009/08/15/a-simple-git-workflow/</link>
		<comments>http://www.kleinsch.com/2009/08/15/a-simple-git-workflow/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 13:59:55 +0000</pubDate>
		<dc:creator>Nick Kleinschmidt</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://kleinsch.com/?p=22</guid>
		<description><![CDATA[Setting up a Git repository is simple. You can use an existing directory or create something from scratch. I'll start out fresh. The 'init' command sets up a new repository.]]></description>
			<content:encoded><![CDATA[<p>I just started using Git for source control. Having used CVS and SVN extensively, I thought I had a decent background on version control and would be able to pick it up quickly. I quickly was overwhelmed by the amount of concepts and explanations needed in the documentation. Hint to the folks writing the <a href="http://book.git-scm.com/">Git book</a>: start with simple concepts and build up from there. I don&#8217;t need to know how Git stores its files in the first chapter. I don&#8217;t need to know what a fast forward merge is. Give me one chapter that has a simple workflow example, then jump into the explanations of the internals and advanced features. I had to read through 50 pages of the book to figure out a basic remote workflow. Here are some of the bits I&#8217;ve gleaned. I&#8217;m still a Git beginner, so tips are always appreciated.</p>
<p>I&#8217;ll assume you have Git set up already, there are tutorials on the web for the wide variety of supported platforms. Once you&#8217;re set up with Git, you should be able to run &#8216;git &#8211;version&#8217; at the command line and see a version string (like &#8220;git version 1.6.3.2&#8243;). All git commands are run in the format &#8216;git COMMAND_NAME OPTIONS&#8217;. Running &#8216;git &#8211;help&#8217; will list all commands. Running &#8216;git help COMMAND_NAME&#8217; will give a man page about that command. For example, to get information about the add command, you can run &#8216;git help add&#8217;.</p>
<p>Setting up a Git repository is simple. You can use an existing directory or create something from scratch. I&#8217;ll start out fresh. The &#8216;init&#8217; command sets up a new repository.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:tmp nick$ <span style="color: #c20cb9; font-weight: bold;">mkdir</span> first <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">cd</span> first
Kleinschs-Macbook:first nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'firstEdit'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file1
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> init</pre></div></div>

<p>Now we&#8217;re set up with a Git repository in this directory. The &#8216;status&#8217; command gives you information about your working set.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> status
<span style="color: #666666; font-style: italic;"># On branch master</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Initial commit</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Untracked files:</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git add ...&quot; to include in what will be committed)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#	file1</span>
nothing added to commit but untracked files present <span style="color: #7a0874; font-weight: bold;">&#40;</span>use <span style="color: #ff0000;">&quot;git add&quot;</span> to track<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>To make a commit in Git, you first do an &#8216;add&#8217; of all files you want to be included in the commit, then a &#8216;commit&#8217;. The commit command will prompt for a message using your favorite editor, or you can use the &#8216;-m&#8217; flag to add the message at the command line.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> add file1
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> status
<span style="color: #666666; font-style: italic;"># On branch master</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Initial commit</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Changes to be committed:</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git rm --cached ...&quot; to unstage)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#	new file:   file1</span>
<span style="color: #666666; font-style: italic;">#</span>
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-m</span><span style="color: #ff0000;">'First commit'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>master <span style="color: #7a0874; font-weight: bold;">&#40;</span>root-commit<span style="color: #7a0874; font-weight: bold;">&#41;</span> 4cc0433<span style="color: #7a0874; font-weight: bold;">&#93;</span> first <span style="color: #c20cb9; font-weight: bold;">file</span>
<span style="color: #000000;">1</span> files changed, <span style="color: #000000;">1</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">0</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
create mode <span style="color: #000000;">100644</span> file1
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> status
<span style="color: #666666; font-style: italic;"># On branch master</span>
nothing to commit <span style="color: #7a0874; font-weight: bold;">&#40;</span>working directory clean<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Let&#8217;s say we want to make a change. We&#8217;ll modify the first file and add another.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'secondEdit'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file1
Kleinschs-Macbook:first nick$ <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">'anotherFile'</span> <span style="color: #000000; font-weight: bold;">&gt;</span> file2
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> status
<span style="color: #666666; font-style: italic;"># On branch master</span>
<span style="color: #666666; font-style: italic;"># Changed but not updated:</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git add ...&quot; to update what will be committed)</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git checkout -- ...&quot; to discard changes in working directory)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#	modified:   file1</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;"># Untracked files:</span>
<span style="color: #666666; font-style: italic;">#   (use &quot;git add ...&quot; to include in what will be committed)</span>
<span style="color: #666666; font-style: italic;">#</span>
<span style="color: #666666; font-style: italic;">#	file2</span>
no changes added to commit <span style="color: #7a0874; font-weight: bold;">&#40;</span>use <span style="color: #ff0000;">&quot;git add&quot;</span> and<span style="color: #000000; font-weight: bold;">/</span>or <span style="color: #ff0000;">&quot;git commit -a&quot;</span><span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>Git detects that we&#8217;ve changed one file and added another. If you want to see the changes you made, you can use the &#8216;diff&#8217; command to show a diff of the files.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> <span style="color: #c20cb9; font-weight: bold;">diff</span> file1
<span style="color: #c20cb9; font-weight: bold;">diff</span> <span style="color: #660033;">--git</span> a<span style="color: #000000; font-weight: bold;">/</span>file1 b<span style="color: #000000; font-weight: bold;">/</span>file1
index dc2bdc4..1837f2f <span style="color: #000000;">100644</span>
<span style="color: #660033;">---</span> a<span style="color: #000000; font-weight: bold;">/</span>file1
+++ b<span style="color: #000000; font-weight: bold;">/</span>file1
<span style="color: #000000; font-weight: bold;">@@</span> <span style="color: #660033;">-1</span> +<span style="color: #000000;">1</span> <span style="color: #000000; font-weight: bold;">@@</span>
<span style="color: #660033;">-firstEdit</span>
+secondEdit</pre></div></div>

<p>We could add the change and commit, but there&#8217;s a slightly easier way. As the status output describes, you can use the &#8216;-a&#8217; flag for commit to automatically commit all modified files. It will not add new files, you&#8217;ll still have to do add those yourself. Let&#8217;s add the second file and commit the whole thing.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> add file2
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> commit <span style="color: #660033;">-am</span><span style="color: #ff0000;">'Made a second commit!'</span>
<span style="color: #7a0874; font-weight: bold;">&#91;</span>master 74ec253<span style="color: #7a0874; font-weight: bold;">&#93;</span> Made a second commit<span style="color: #000000; font-weight: bold;">!</span>
<span style="color: #000000;">2</span> files changed, <span style="color: #000000;">2</span> insertions<span style="color: #7a0874; font-weight: bold;">&#40;</span>+<span style="color: #7a0874; font-weight: bold;">&#41;</span>, <span style="color: #000000;">1</span> deletions<span style="color: #7a0874; font-weight: bold;">&#40;</span>-<span style="color: #7a0874; font-weight: bold;">&#41;</span>
create mode <span style="color: #000000;">100644</span> file2
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> status
<span style="color: #666666; font-style: italic;"># On branch master</span>
nothing to commit <span style="color: #7a0874; font-weight: bold;">&#40;</span>working directory clean<span style="color: #7a0874; font-weight: bold;">&#41;</span></pre></div></div>

<p>The last thing to cover for right now is looking at past history. You use the &#8216;log&#8217; command to view commit history.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> log file1
commit 8ebf88b3d99309c1bd245156459a24549cf11ee8
Author: Nick Kleinschmidt <span style="color: #000000; font-weight: bold;">&lt;</span>nick.kleinschmidt<span style="color: #000000; font-weight: bold;">@</span>gmail.com<span style="color: #000000; font-weight: bold;">&gt;</span>
Date:   Sat Aug <span style="color: #000000;">15</span> 09:<span style="color: #000000;">28</span>:<span style="color: #000000;">26</span> <span style="color: #000000;">2009</span> <span style="color: #660033;">-0400</span>
&nbsp;
    Made a second commit<span style="color: #000000; font-weight: bold;">!</span>
&nbsp;
commit 7801dc66b2b3b5029e888ad35e5f0405584b4ff1
Author: Nick Kleinschmidt <span style="color: #000000; font-weight: bold;">&lt;</span>nick.kleinschmidt<span style="color: #000000; font-weight: bold;">@</span>gmail.com<span style="color: #000000; font-weight: bold;">&gt;</span>
Date:   Sat Aug <span style="color: #000000;">15</span> 09:<span style="color: #000000;">24</span>:<span style="color: #000000;">47</span> <span style="color: #000000;">2009</span> <span style="color: #660033;">-0400</span>
&nbsp;
    first commit
Kleinschs-Macbook:first nick$ <span style="color: #c20cb9; font-weight: bold;">git</span> log file2
commit 8ebf88b3d99309c1bd245156459a24549cf11ee8
Author: Nick Kleinschmidt <span style="color: #000000; font-weight: bold;">&lt;</span>nick.kleinschmidt<span style="color: #000000; font-weight: bold;">@</span>gmail.com<span style="color: #000000; font-weight: bold;">&gt;</span>
Date:   Sat Aug <span style="color: #000000;">15</span> 09:<span style="color: #000000;">28</span>:<span style="color: #000000;">26</span> <span style="color: #000000;">2009</span> <span style="color: #660033;">-0400</span>
&nbsp;
    Made a second commit<span style="color: #000000; font-weight: bold;">!</span></pre></div></div>

<p>With this setup, you can work locally, changing and committing to your hearts content. At this point, it&#8217;s fairly similar to most traditional version control systems. There&#8217;s still a lot to cover! Next time, I&#8217;ll get into setting up a remote repository, then we&#8217;ll dive into branching and merging.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kleinsch.com/2009/08/15/a-simple-git-workflow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Setting up WordPress on Debian 5.0</title>
		<link>http://www.kleinsch.com/2009/08/01/setting-up-wordpress-on-debian-5-0/</link>
		<comments>http://www.kleinsch.com/2009/08/01/setting-up-wordpress-on-debian-5-0/#comments</comments>
		<pubDate>Sat, 01 Aug 2009 16:07:45 +0000</pubDate>
		<dc:creator>Nick Kleinschmidt</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://kleinsch.com/?p=6</guid>
		<description><![CDATA[I'll assume you're starting with a stock Debian 5.0 system and have set up sudo access for your account. I'll be using the user nick as my personal user for this setup.

First we need install the prerequisites: Apache, PHP, and MySQL. It'll ask you for a root password for MySQL, make sure you hold onto that. We'll need it later.]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ll assume you&#8217;re starting with a stock Debian 5.0 system and have set up sudo access for your account. I&#8217;ll be using the user nick as my personal user for this setup.</p>
<p>First we need install the prerequisites: Apache, PHP, and MySQL. It&#8217;ll ask you for a root password for MySQL, make sure you hold onto that. We&#8217;ll need it later.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">apt-get</span> <span style="color: #c20cb9; font-weight: bold;">install</span> apache2 mysql-server php5 php5-mysql</pre></div></div>

<p>Now we need to make sure that Apache is configured with the modules needed for WordPress.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> a2enmod rewrite
<span style="color: #c20cb9; font-weight: bold;">sudo</span> a2enmod php5</pre></div></div>

<p>WordPress uses a MySQL database to store your blog posts and comments, so we need to create a MySQL database for wordpress. MySQL will ask you for the root password you created before. Make sure to save the password you set up for the wordpress user, as this is what WordPress will use to connect to the database.</p>

<div class="wp_syntax"><div class="code"><pre class="mysql" style="font-family:monospace;">mysql <span style="color: #CC0099;">-</span>u root <span style="color: #CC0099;">-</span>p
<span style="color: #990099; font-weight: bold;">CREATE</span> <span style="color: #990099; font-weight: bold;">DATABASE</span> <span style="color: #008000;">`wordpress`</span><span style="color: #000033;">;</span>
<span style="color: #990099; font-weight: bold;">grant</span> <span style="color: #990099; font-weight: bold;">all</span> <span style="color: #990099; font-weight: bold;">privileges</span> <span style="color: #990099; font-weight: bold;">on</span> <span style="color: #008000;">`wordpress`</span>.<span style="color: #CC0099;">*</span> <span style="color: #990099; font-weight: bold;">to</span> <span style="color: #008000;">'wordpress'</span>@localhost identified by <span style="color: #008000;">'ANOTHER-PASSWORD'</span><span style="color: #000033;">;</span> 
flush <span style="color: #990099; font-weight: bold;">privileges</span><span style="color: #000033;">;</span></pre></div></div>

<p>Need to set up WordPress with a directory so we can use it. Download WordPress from their <a href="http://wordpress.org/download/">site</a> and stick it in your home directory.</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">cd</span> <span style="color: #000000; font-weight: bold;">/</span>var<span style="color: #000000; font-weight: bold;">/</span>www
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">mkdir</span> sites <span style="color: #000000; font-weight: bold;">&amp;&amp;</span> <span style="color: #7a0874; font-weight: bold;">cd</span> sites
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">cp</span> ~nick<span style="color: #000000; font-weight: bold;">/</span>wordpress-2.8.2.tar.gz .
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">tar</span> xzvf wordpress-2.8.2.tar.gz
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">touch</span> wordpress<span style="color: #000000; font-weight: bold;">/</span>.htaccess
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> nick:www-data wordpress
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">chmod</span> <span style="color: #660033;">-R</span> g+<span style="color: #c20cb9; font-weight: bold;">w</span> wordpress</pre></div></div>

<p>We changed the group and gave write permissions so WordPress will be able to set up its own config files. We set up the .htaccess file in advance because it&#8217;s easier to let WordPress change it based on the URL settings.</p>
<p>In order to serve the website, we need to set up an Apache Virtual Host. Create a file in /etc/apache/sites-available (mine is kleinsch.com) for your site and add the following code.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;VirtualHost</span> *:80<span style="color: #000000; font-weight: bold;">&gt;</span></span>
        ServerName kleinsch.com
        ServerAlias www.kleinsch.com
        ServerAdmin youremail@yourhost.com
        DocumentRoot /var/www/sites/wordpress
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;Directory</span> /var/www/sites/wordpress<span style="color: #000000; font-weight: bold;">&gt;</span></span>
                Options FollowSymLinks
                AllowOverride All
        <span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/Directory<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>
<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/VirtualHost<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Enable the site within Apache and restart:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> a2ensite kleinsch.com
<span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>apache restart</pre></div></div>

<p>You should see no warnings. Open up your browser and navigate to &#8216;http://yoursite.com/wp-admin/install.php&#8217;.</p>
<p>The first page will tell you WordPress needs to create a config file, we want it to do that. On the next page, enter the database information you set up above. Leave the defaults for the encoding and table prefix. Enter a title for your blog, and you&#8217;re up and running!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.kleinsch.com/2009/08/01/setting-up-wordpress-on-debian-5-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss><!-- Dynamic page generated in 1.096 seconds. --><!-- Cached page generated by WP-Super-Cache on 2012-02-10 05:47:06 --><!-- Compression = gzip -->

