<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Floorplanner Tech Blog &#187; push</title>
	<atom:link href="http://techblog.floorplanner.com/tag/push/feed/" rel="self" type="application/rss+xml" />
	<link>http://techblog.floorplanner.com</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Fri, 05 Mar 2010 20:29:03 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Working with git branches</title>
		<link>http://techblog.floorplanner.com/2008/12/14/working-with-git-branches/</link>
		<comments>http://techblog.floorplanner.com/2008/12/14/working-with-git-branches/#comments</comments>
		<pubDate>Sun, 14 Dec 2008 17:33:16 +0000</pubDate>
		<dc:creator>Willem van Bergen</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[bash colors]]></category>
		<category><![CDATA[branches]]></category>
		<category><![CDATA[checkout]]></category>
		<category><![CDATA[git]]></category>
		<category><![CDATA[origin]]></category>
		<category><![CDATA[pull]]></category>
		<category><![CDATA[push]]></category>
		<category><![CDATA[remote]]></category>

		<guid isPermaLink="false">http://techblog.floorplanner.com/?p=321</guid>
		<description><![CDATA[
			
				
			
		
Because Jaap finally convinced Gert-Jan, we have moved to the Git version control system for the main Floorplanner repository. Now we can use branches for different functionality far more easily. As an easy reminder to some common Git tasks I will need regularly, I have written down some Git recipes. This is basically meant for [...]]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="float: right; margin-left: 10px;">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F12%2F14%2Fworking-with-git-branches%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Ftechblog.floorplanner.com%2F2008%2F12%2F14%2Fworking-with-git-branches%2F&amp;style=normal" height="61" width="50" /><br />
			</a>
		</div>
<p>Because <a href="http://techblog.floorplanner.com/2008/12/09/git-vs-svn-for-bosses">Jaap finally convinced Gert-Jan</a>, we have moved to the Git version control system for the main Floorplanner repository. Now we can use branches for different functionality far more easily. As an easy reminder to some common Git tasks I will need regularly, I have written down some Git recipes. This is basically meant for me and my fellow developers, but maybe it can help you as well. Suggestions to improve my workflow are welcome!</p>
<h3>Displaying the current branch in your prompt</h3>
<p>Because I will be using branches more regularly now, it is nice to know what branch I am currently working in. <code>git branch</code> will provide this information, but it can be more direct by including the current branch in your terminal prompt. </p>
<p>To display the current git branch in my terminal prompt, I have added <a href="http://gist.github.com/5017"> the following</a> to my Bash configuration file <code>~/.profile</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family: Monaco,monospace;">parse_git_branch() {
  git branch 2&gt; /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ \[\1\]/'
}
&nbsp;
PS1='\[\033[01;37m\]\w\[\033[00;35m\]$(parse_git_branch)\[\033[00m\] \$ '</pre></div></div>

<p>I use a black, semi-transparent terminal with white text, and pink branch names. <a href="http://www.systhread.net/texts/200703bashish.php">Change the colors</a> to your own liking!</p>
<p><img src="http://techblog.floorplanner.com/wp-content/uploads/2008/12/picture-4.png" alt="Git - branch in terminal" title="Git - branch in terminal" width="574" height="395" class="alignnone size-full wp-image-349" /></p>
<h3>Working on a remote branch that is not available locally yet</h3>
<p>If you want to help out on a branch that somebody else started and has pushed it to the remote repository, you can checkout this branch and make it &#8220;track&#8221; the remote branch.</p>

<div class="wp_syntax"><div class="code"><pre class="shell" style="font-family: Monaco,monospace;">$ git checkout -b newbranch origin/newbranch</pre></div></div>

<p>In this example, <strong>origin/newbranch</strong> is the branch in the remote repository. Locally, this branch will be called <strong >newbranch</strong >. A simple <code>git pull</code> will update my branch with the latest changes from the remote branch later on, <code>git push</code> will send my changes to the remote server. </p>
<p><img src="http://techblog.floorplanner.com/wp-content/uploads/2008/12/picture-1.png" alt="Git - track remote branch" title="Git - track remote branch" width="574" height="395" class="alignnone size-full wp-image-336" /></p>
<h3>Creating a new branch and pushing it to the remote server</h3>
<p>Sometimes I want to start a new branch myself if I want to work on a new feature or on disruptive refactoring of the main codebase.</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family: Monaco,monospace;">$ git checkout -b feature</pre></div></div>

<p>The <em>feature</em> branch is now available locally. After some time, I want to share my current changes in this branch with other developers. I should make the branch available in the remote repository so other can access it like I described above.</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family: Monaco,monospace;">$ git commit -m &quot;Added initial version of %feature%&quot;
$ git push origin feature</pre></div></div>

<p><img src="http://techblog.floorplanner.com/wp-content/uploads/2008/12/picture-2.png" alt="Git - push local branch to remote" title="Git - push local branch to remote" width="574" height="395" class="alignnone size-full wp-image-341" /></p>
<p>The feature branch will now be available to other developers as well. Note that the local <em>feature</em>-branch is <strong>not</strong> tracking the remote branch of the same name. This can be enabled by <a href="http://graysky.org/2008/12/git-branch-auto-tracking/">changing the configuration</a> of the repository.</p>
<h3>Merging a branch</h3>
<p>After work is completed on my <em>feature</em>-branch and it is tested thoroughly, I want to merge the branch with the master branch of the project. To make sure the merge with the master branch is seamless and all possible merge conflicts are handled beforehand, we first run <code>git rebase</code>. This ensures that the changes in the <em>feature</em> branch are relative to the latest commit to the master branch and can therefore be applied by a &#8220;fast forward&#8221;. It is best to run <code>git rebase</code> from time time to time while you are developing in the <em>feature</em> branch to make sure your work does not divert to much from the main development in the master branch.</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family: Monaco,monospace;">  # make sure that the current branch is seamlessly
  # mergeable with the master branch
$ git rebase master
  # switch to the master branch
$ git checkout master
  # now, merge the feature branch
$ git merge feature
  # publish the merge to the remote server
$ git push origin master</pre></div></div>

<p><img src="http://techblog.floorplanner.com/wp-content/uploads/2008/12/picture-3.png" alt="Git - merge branch" title="Git - merge branch" width="574" height="395" class="alignnone size-full wp-image-343" /></p>
<p>I can now delete the local and remote feature branch, as the changes have been incorporated in the master branch:</p>

<div class="wp_syntax"><div class="code"><pre class="sh" style="font-family: Monaco,monospace;">$ git branch -d feature
$ git branch -d -r origin/feature</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://techblog.floorplanner.com/2008/12/14/working-with-git-branches/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
