<?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>Yan Pritzker &#187; git</title>
	<atom:link href="http://yanpritzker.com/category/git/feed/" rel="self" type="application/rss+xml" />
	<link>http://yanpritzker.com</link>
	<description>photographer, entrepreneur, software engineer, musician, skier</description>
	<lastBuildDate>Thu, 26 Apr 2012 18:11:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<atom:link rel="next" href="http://yanpritzker.com/category/git/feed/?page=2" />

		<item>
		<title>Dotfiles for insane productivity in bash, git, and vim</title>
		<link>http://yanpritzker.com/2011/11/17/dotfiles-for-ultimate-productivity-in-bash-and-vim/</link>
		<comments>http://yanpritzker.com/2011/11/17/dotfiles-for-ultimate-productivity-in-bash-and-vim/#comments</comments>
		<pubDate>Thu, 17 Nov 2011 22:59:57 +0000</pubDate>
		<dc:creator>yan</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://yanpritzker.com/?p=356</guid>
		<description><![CDATA[Following the principles of insane productivity that I blogged about earlier, I am releasing my dotfile repository, containing customizations for bash, git, and vim. The guiding principles are two letter mnemonics for everything bash and git related, and single letter capital letter actions for all common Vim commands. The selection of vim plugins is best [...]]]></description>
			<content:encoded><![CDATA[<p>Following the principles of <a href="http://yanpritzker.com/2006/10/03/five-ways-to-get-insane-productivity-boosts/">insane productivity</a> that I blogged about earlier, I am releasing my <a href="http://github.com/skwp/dotfiles">dotfile repository</a>, containing customizations for bash, git, and vim.</a> The guiding principles are two letter mnemonics for everything bash and git related, and single letter capital letter actions for all common Vim commands. The selection of vim plugins is best of breed for navigation, color highlighting, and git integration. The vim setup is optimized for rails and git development. The vimrc contains my custom single-letter aliases and is pretty well commented, so that you can easily take or reject my modifications as you need. and I will continue to clean up the repo and move everything into tpope&#8217;s pathogen plugin format over time. Enjoy and please send feedback!</p>
<div class="plus-one-wrap"><g:plusone href="http://yanpritzker.com/2011/11/17/dotfiles-for-ultimate-productivity-in-bash-and-vim/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://yanpritzker.com/2011/11/17/dotfiles-for-ultimate-productivity-in-bash-and-vim/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>vim/rails/git: find references to current partial</title>
		<link>http://yanpritzker.com/2011/10/31/vimrailsgit-find-references-to-current-partial/</link>
		<comments>http://yanpritzker.com/2011/10/31/vimrailsgit-find-references-to-current-partial/#comments</comments>
		<pubDate>Mon, 31 Oct 2011 16:34:57 +0000</pubDate>
		<dc:creator>yan</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://yanpritzker.com/?p=344</guid>
		<description><![CDATA[Update 12/15/2011: Released as a plugin on github Blazing fast way of finding references to the current partial you&#8217;re viewing using this simple script. Requires git-grep.vim. Bonus: at the bottom of the script I also define &#8220;K&#8221; to git grep the current word. Very handy for fast function reference finding. Like this post? Here are [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update 12/15/2011: Released as a plugin <a href="https://github.com/skwp/vim-git-grep-rails-partial">on github</a></strong></p>
<p>Blazing fast way of finding references to the current partial you&#8217;re viewing using this simple script. Requires <a href="https://github.com/tjennings/git-grep-vim">git-grep.vim</a>. Bonus: at the bottom of the script I also define &#8220;K&#8221; to git grep the current word. Very handy for fast function reference finding.</p>
<p><script src="https://gist.github.com/1327904.js?file=git_grep_partial.vim"></script></p>
<p>Like this post? Here are some more you might enjoy:</p>
<ul>
<li><a href="http://yanpritzker.com/2006/10/03/five-ways-to-get-insane-productivity-boosts/">Five ways to get insane productivity boosts</a></li>
<li><a href="http://yanpritzker.com/2011/10/26/colorful-vim-ruby-tests-and-debugging/">Colorful ruby tests and debugging</a></li>
</ul>
<div class="plus-one-wrap"><g:plusone href="http://yanpritzker.com/2011/10/31/vimrailsgit-find-references-to-current-partial/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://yanpritzker.com/2011/10/31/vimrailsgit-find-references-to-current-partial/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Git Workflows Book</title>
		<link>http://yanpritzker.com/2011/10/12/git-workflows-book/</link>
		<comments>http://yanpritzker.com/2011/10/12/git-workflows-book/#comments</comments>
		<pubDate>Wed, 12 Oct 2011 21:54:39 +0000</pubDate>
		<dc:creator>yan</dc:creator>
				<category><![CDATA[git]]></category>

		<guid isPermaLink="false">http://yanpritzker.com/2011/10/12/git-workflows-book/</guid>
		<description><![CDATA[About a year ago, I was working with PeepCode to create a Git Workflows screencast based on a short git workflows book that I had written, a no-nonsense guide to using git for remote collaboration. Unfortunately I had to abandon the project due to lack of time, but the book remains alive, and is more [...]]]></description>
			<content:encoded><![CDATA[<p>About a year ago, I was working with PeepCode to create a Git Workflows screencast based on a short git workflows book that I had written, a no-nonsense guide to using git for remote collaboration.  </p>
<p>Unfortunately I had to abandon the project due to lack of time, but the book remains alive, and is more or less accurate to the current version of git:</p>
<p>Please enjoy the book for free: <a href="http://yanpritzker.com/git-book/">The Git Workflows Book</a> and feel free to comment on that page with your own thoughts, corrections, and favorite workflows.</p>
<p>Update: the url to the book is updated to a nicer format and ability to leave comments.</p>
<p>Update 2: I am mentioned on the <a href="http://ruby5.envylabs.com/">Ruby 5 podcast</a>! Thanks guys :) </p>
<div class="plus-one-wrap"><g:plusone href="http://yanpritzker.com/2011/10/12/git-workflows-book/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://yanpritzker.com/2011/10/12/git-workflows-book/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Git rm pending files</title>
		<link>http://yanpritzker.com/2008/06/10/git-rm-pending-files/</link>
		<comments>http://yanpritzker.com/2008/06/10/git-rm-pending-files/#comments</comments>
		<pubDate>Tue, 10 Jun 2008 06:28:55 +0000</pubDate>
		<dc:creator>yan</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://skwpspace.com/?p=165</guid>
		<description><![CDATA[If you&#8217;ve deleted a bunch of files in your directory, here&#8217;s a handy bash alias to git rm the changes into your index. alias gitrm="git stat &#124; grep deleted &#124; awk '{print $3}' &#124; xargs git rm" Update: turns out git add -u takes care of deleted files.]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve deleted a bunch of files in your directory, here&#8217;s a handy bash alias to <code>git rm</code> the changes into your index.</p>
<p><strike><br />
<code><br />
alias gitrm="git stat | grep deleted | awk '{print $3}' | xargs git rm"<br />
</code><br />
</strike></p>
<p><b>Update:</b> turns out <code>git add -u</code> takes care of deleted files.</p>
<div class="plus-one-wrap"><g:plusone href="http://yanpritzker.com/2008/06/10/git-rm-pending-files/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://yanpritzker.com/2008/06/10/git-rm-pending-files/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>GitHub is leading us to an opensource renaissance</title>
		<link>http://yanpritzker.com/2008/06/03/github-is-leading-us-to-an-opensource-renaissance/</link>
		<comments>http://yanpritzker.com/2008/06/03/github-is-leading-us-to-an-opensource-renaissance/#comments</comments>
		<pubDate>Tue, 03 Jun 2008 02:46:20 +0000</pubDate>
		<dc:creator>yan</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[startups]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://skwpspace.com/?p=161</guid>
		<description><![CDATA[Before GitHub, if you had something to contribute to an open source project, you basically had to worry about tracking your changes against someone else&#8217;s remote repo, which was usually svn or similar, which was difficult and cumbersome. And even if you did manage to have enough motivation to properly track, format, and email the [...]]]></description>
			<content:encoded><![CDATA[<p>Before GitHub, if you had something to contribute to an open source project, you basically had to worry about tracking your changes against someone else&#8217;s remote repo, which was usually svn or similar, which was difficult and cumbersome. And even if you did manage to have enough motivation to properly track, format, and email the author your patches, he then had to go and integrate your patches which was also difficult and cumbersome.</p>
<p>What&#8217;s nice about GitHub is that first, it gives you an easy way to fork anyone&#8217;s codebase. The key feature of GitHub is <em>fork network tracking</em>, which lets you see everyone else who&#8217;s cloned a particular repo, and what changes they have made. The big benefit is that this prevents you from re-inventing the wheel when you see that someone is already working on the same feature you&#8217;re trying to submit. Instead of going and doing your own thing, you fork off of them and work with them. You might even fork off of a grandchild of the original project just because it has some feature that you need. It&#8217;s like the long tail of open source..you no longer have to wait for the original author to implement your obscure changes. Just find what you want out there and work with it.</p>
<p>The reciprocal benefit of this, of course, is that the original author can actually watch your changes as you&#8217;re making them. Instead of some disjointed patches, he sees your commits as you add them to your own line and can follow your progress visually. At some point, if the author likes your work he can merge your branch back into his code. And GitHub will show this on the network, so everyone else who is following the project can benefit. They&#8217;ve made it easy to notify the author that you have some good changes as well, with the pull request.</p>
<p>This very simple idea of tracking the forking network of a particular project, and doing it well, is why GitHub has made a radically cool contribution to the opensource community. Every day, more and more projects are added to the hub. And it&#8217;s viral&#8230;people who want to contribute to projects request that the project be put on GitHub because it&#8217;s the easiest way to track your contributions. Kudos to GitHub!</p>
<div class="plus-one-wrap"><g:plusone href="http://yanpritzker.com/2008/06/03/github-is-leading-us-to-an-opensource-renaissance/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://yanpritzker.com/2008/06/03/github-is-leading-us-to-an-opensource-renaissance/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Helpful shortcuts for git svn</title>
		<link>http://yanpritzker.com/2008/05/28/helpful-shortcuts-for-git-svn/</link>
		<comments>http://yanpritzker.com/2008/05/28/helpful-shortcuts-for-git-svn/#comments</comments>
		<pubDate>Wed, 28 May 2008 03:06:59 +0000</pubDate>
		<dc:creator>yan</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://skwpspace.com/?p=159</guid>
		<description><![CDATA[Tired of having to stash your changes when you want to grab the latest from svn or want to dcommit one file while keeping others in your working tree? In your bash profile: alias svnpull='git stash &#038;&#038; git svn rebase &#038;&#038; git stash apply' alias svnpush='git stash &#038;&#038; git svn dcommit &#038;&#038; git stash apply']]></description>
			<content:encoded><![CDATA[<p>Tired of having to stash your changes when you want to grab the latest from svn or want to dcommit one file while keeping others in your working tree?</p>
<p>In your bash profile:</p>
<pre><code>
alias svnpull='git stash &#038;&#038; git svn rebase &#038;&#038; git stash apply'
alias svnpush='git stash &#038;&#038; git svn dcommit &#038;&#038; git stash apply'
</code></pre>
<div class="plus-one-wrap"><g:plusone href="http://yanpritzker.com/2008/05/28/helpful-shortcuts-for-git-svn/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://yanpritzker.com/2008/05/28/helpful-shortcuts-for-git-svn/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git tips &amp; tricks part 4: more on cherry picking</title>
		<link>http://yanpritzker.com/2008/05/13/git-tips-tricks-part-4-more-on-cherry-picking/</link>
		<comments>http://yanpritzker.com/2008/05/13/git-tips-tricks-part-4-more-on-cherry-picking/#comments</comments>
		<pubDate>Tue, 13 May 2008 21:06:02 +0000</pubDate>
		<dc:creator>yan</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://skwpspace.com/?p=152</guid>
		<description><![CDATA[In my previous post I discussed how it was possible to merge individual changes from one branch to another. At that time I mentioned using the log on the original branch to figure out which changes were available to merge, but it turns out there&#8217;s an easier way. Let&#8217;s say you made some changes in [...]]]></description>
			<content:encoded><![CDATA[<p>In my <a href="http://skwpspace.com/2008/05/13/git-tips-and-tricks-part-3-working-with-svn-branches-and-cherry-pick/">previous post</a> I discussed how it was possible to merge individual changes from one branch to another. At that time I mentioned using the log on the original branch to figure out which changes were available to merge, but it turns out there&#8217;s an easier way.</p>
<p>Let&#8217;s say you made some changes in local-trunk and you want to merge them into your branch-1.5 which is your release branch. From the branch:</p>
<p><code>
<pre>
git cherry -v local-trunk
+ 08d7780de7e16a22b7e8ed1d42acebc4bc07573f  a changeset i haven't merged yet
- 78a7b285089c76664a530f68803259c53cbadb42 another change
</pre>
<p></code></p>
<p>Each line indicates a change. If it has a &#8220;+&#8221; it means they only exist in the local-trunk. A minus indicates changes that have already been merged in. Magic! Now that you know which changes you want, just cherry-pick them in.</p>
<p><code>git cherry-pick 08d7780de</code></p>
<p><b>Update:</b> here&#8217;s another cool trick to see where every branch is at</p>
<p><code>git branch -v</code></p>
<p>Output looks like this:</p>
<pre>
branch        317544a #520 fix single page build<br />
local-trunk   ec85f65 #520 fix single page build</p>
<pre>
<div class="plus-one-wrap"><g:plusone href="http://yanpritzker.com/2008/05/13/git-tips-tricks-part-4-more-on-cherry-picking/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://yanpritzker.com/2008/05/13/git-tips-tricks-part-4-more-on-cherry-picking/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Git tips and tricks part 3: working with svn branches and cherry-pick</title>
		<link>http://yanpritzker.com/2008/05/13/git-tips-and-tricks-part-3-working-with-svn-branches-and-cherry-pick/</link>
		<comments>http://yanpritzker.com/2008/05/13/git-tips-and-tricks-part-3-working-with-svn-branches-and-cherry-pick/#comments</comments>
		<pubDate>Tue, 13 May 2008 03:37:01 +0000</pubDate>
		<dc:creator>yan</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[scm]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[textmate]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[yahoo]]></category>

		<guid isPermaLink="false">http://skwpspace.com/?p=151</guid>
		<description><![CDATA[After several weeks of git usage, I&#8217;ve developed a nice workflow. First, we&#8217;ll start with working with several svn branches via git. Working with svn branches via git Assuming you&#8217;ve properly cloned your svn repository, you should have your trunk and remote branches fetched from svn. You can see the remote branches via git branch [...]]]></description>
			<content:encoded><![CDATA[<p>After several weeks of git usage, I&#8217;ve developed a nice workflow. First, we&#8217;ll start with working with several svn branches via git.</p>
<p><b>Working with svn branches via git</b></p>
<p>Assuming you&#8217;ve properly cloned your svn repository, you should have your trunk and remote branches fetched from svn. You can see the remote branches via </p>
<p><code>git branch -r</code></p>
<p>If you have colorization turned on, then</p>
<p><code>git branch -a </code></p>
<p>Will give you all your branches (local and remote) and color the remote ones in red. The way you want to work is to create a local git branch for every svn branch you&#8217;re working with. So you might do something like</p>
<p><code>git branch local-trunk trunk</code><br />
<code>git branch local-1.5 branches/1.5</code></p>
<p>This will create two local branches (called local-trunk, and local-1.5 respectively) that follow the corresponding remote branches (trunk, and branches/1.5).</p>
<p>Now we&#8217;ll switch to the trunk&#8230;</p>
<p><code>git checkout local-trunk</code></p>
<p>Do some hacking, and commit the change</p>
<p><code>git commit -a -m "this is my hack"</code></p>
<p>Let&#8217;s say this was a bugfix and you also need to apply it to the branch. Switch to the branch:</p>
<p><code>git checkout local-1.5</code></p>
<p>To pull individual fixes from trunk you can cherry-pick the fix by its commit hash, which you obtained when you committed or via a log.</p>
<p><code>git cherry-pick 234adsfa7s8dfasdf</code></p>
<p>This will automatically pull in the change and commit it to your branch. If you don&#8217;t want to immediately commit but want to mess with the files first, then use the <code>-n</code> switch, which merges in the fix but doesn&#8217;t commit it. Then you&#8217;ll want to <code>git svn dcommit</code> to push your change out to the svn branch. This procedure is much faster than using svnmerge.py.</p>
<p><b>Nonstandard or wacky branch structure</b></p>
<p>It so happens that my repository is set up in a slightly nonstandard way due to a particular legacy. Instead of having a structure such as foo/trunk and foo/branches, I have trunk/foo and branches/[branchname]/foo. As it turns out, git supports this very well as long as you specify the format using wildcards in your <code>.git/config</code></p>
<p><code>
<pre>
[svn-remote "svn"]
  url = http://www.myrepo.com/svn/parent
  fetch = trunk/foo:refs/remotes/foo/trunk
  branches = branches/*/foo:refs/remotes/foo/branches/*
</pre>
<p></code></p>
<p>The format of this file basically has two parts separated by a colon. The first part tells git what the repo looks on the svn side. The second tells it what to call the branches that git creates to correspond to the ones out in svn. You&#8217;ll notice the placement of the wildcard on the third line is what generates all the branches correctly.</p>
<p><b>Note:</b> Please see <a href="http://skwpspace.com/category/git/">all posts tagged git</a> for the rest of the series.</p>
<div class="plus-one-wrap"><g:plusone href="http://yanpritzker.com/2008/05/13/git-tips-and-tricks-part-3-working-with-svn-branches-and-cherry-pick/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://yanpritzker.com/2008/05/13/git-tips-and-tricks-part-3-working-with-svn-branches-and-cherry-pick/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>More git tips and tricks</title>
		<link>http://yanpritzker.com/2008/05/01/more-git-tips-and-tricks/</link>
		<comments>http://yanpritzker.com/2008/05/01/more-git-tips-and-tricks/#comments</comments>
		<pubDate>Thu, 01 May 2008 21:05:51 +0000</pubDate>
		<dc:creator>yan</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[thoughts]]></category>

		<guid isPermaLink="false">http://skwpspace.com/?p=147</guid>
		<description><![CDATA[Here are a couple more fun git commands and configuration tricks. Make some aliases because typing &#8216;checkout&#8217; is a pain. In ~/.gitconfig: Note the quicklog command below uses a custom log format which shows you a short hash, a relative date (&#8220;4 hours ago&#8221;) and the commit message. I created it by reading the git [...]]]></description>
			<content:encoded><![CDATA[<p>Here are a couple more fun git commands and configuration tricks.</p>
<p>Make some aliases because typing &#8216;checkout&#8217; is a pain. In ~/.gitconfig:<br />
Note the quicklog command below uses a custom log format which shows you a short hash, a relative date (&#8220;4 hours ago&#8221;) and the commit message. I created it by reading the <a href="http://www.kernel.org/pub/software/scm/git/docs/git-whatchanged.html">git log formatting manpage</a>.</p>
<pre>
<code>
[alias]
  ci = commit
  co = checkout
  b = branch
  nb = checkout -b
  stat = status
  sl = stash list
  sa = stash apply
  sd = stash drop
  quicklog = log --pretty=format:\"%h %cr %cn %Cgreen%s%Creset\"
  changes = log --pretty=oneline
  svnup = svn rebase
  svnpush = svn dcommit
</code>
</pre>
<p>I really love the &#8216;nb&#8217; alias, which I use to mean &#8216;new branch&#8217;. It lets me very quickly create and switch to a new branch &#8220;git nb fixing_bug_123&#8243;.</p>
<p>Display the current branch in your bash prompt. Modified from <a href="http://acts.as.streeteasy.com/archives/2007/12/19/git_in_your_prompt/">here.</a></p>
<pre><code>
export MANPATH=/usr/local/git/man:$MANPATH
 function parse_git_branch {
   git branch 2> /dev/null | \
	sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1) /'
 }
export PS1='\u@\H:\w $(parse_git_branch)$ '
</code></pre>
<p>Get a nice list of change summaries, one line per change</p>
<p><code>git log --pretty=oneline --since="2 weeks ago" --until="yesterday"</code></p>
<p>See what changed from one commit set to another (these can be branch names)</p>
<p><code>git log my-branch..master</code></p>
<p>See which files changed in the log</p>
<p><code>git log --name-status</code></p>
<p>Browse your local repo with a web interface</p>
<p><code>git instaweb --httpd=webrick</code></p>
<p>Want to reorder previous commits, squash commits, and generally wreak havoc?<br />
The following command opens up an interactive editor with the last 10 commits.</p>
<p><code>git rebase -i HEAD~10</code></p>
<div class="plus-one-wrap"><g:plusone href="http://yanpritzker.com/2008/05/01/more-git-tips-and-tricks/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://yanpritzker.com/2008/05/01/more-git-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Useful git commands and quirks</title>
		<link>http://yanpritzker.com/2008/04/22/useful-git-commands-and-quirks/</link>
		<comments>http://yanpritzker.com/2008/04/22/useful-git-commands-and-quirks/#comments</comments>
		<pubDate>Tue, 22 Apr 2008 05:00:34 +0000</pubDate>
		<dc:creator>yan</dc:creator>
				<category><![CDATA[git]]></category>
		<category><![CDATA[sourcecontrol]]></category>
		<category><![CDATA[svn]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://skwpspace.com/2008/04/22/useful-git-commands-and-quirks/</guid>
		<description><![CDATA[Things I&#8217;ve learned from my first git experiences. First of all, git is inconsistent as hell. Every command has its own quirks and syntax, so I&#8217;m attempting to catalog some of them here. We&#8217;ve been using git svn at Planypus as a way to maintain local developer branches and still push to our svn as [...]]]></description>
			<content:encoded><![CDATA[<p>Things I&#8217;ve learned from my first git experiences. First of all, git is inconsistent as hell. Every command has its own quirks and syntax, so I&#8217;m attempting to catalog some of them here. We&#8217;ve been using <code>git svn</code> at Planypus as a way to maintain local developer branches and still push to our svn as a central place which then triggers our integration server rebuild, cruise control, and so on.</p>
<p><b>First, make it look nice</b><br />
<code><br />
$ git config --global color.diff auto<br />
$ git config --global color.status auto<br />
$ git config --global color.branch auto<br />
$ git config --global color.interactive auto<br />
</code><br />
via <a href="http://www.tpope.net/rails-git-best-practices">tpope</a></p>
<p><b>Onwards to the commands&#8230;</b></p>
<p>If you&#8217;re using <code>git svn</code> and you want to see changes that you have comitted locally but have not yet <code>dcomitt</code>ed</p>
<p><code>git svn dcommit -n</code></p>
<p>This might give you output that looks like this<br />
<code>diff-tree e784cfa... e784cfa...</code></p>
<p>BUT, if you want to actually see the changes, what you want is apparently the &#8216;patch&#8217; output:</p>
<p><code>git diff-tree -p e784cfa... e784cfa...</code></p>
<p>If you have uncomitted changes, it&#8217;s easy to see them</p>
<p><code>git diff</code></p>
<p>BUT, if you&#8217;ve already created your commit set (<code>git add</code>) but not comitted, you how have to use</p>
<p><code>git diff --cached</code></p>
<p>If you&#8217;ve accidentally added  some files to your commit set and want to remove them from the index (untrack them), but leave the changes in your working tree</p>
<p><code>git reset HEAD [file/dir]</code></p>
<p>To undo local changes (<em>revert</em> in the svn sense)</p>
<p><code>git checkout [files]</code></p>
<p>Note that this works as long as the file is not yet in your index. If you&#8217;re already tracking it for commit, you&#8217;ll need to untrack it first using <code>git reset HEAD [file]</code> before you&#8217;re able to check it out.</p>
<p>You can also use this command to check out files from the past by specifying any commit hash:</p>
<p><code>git checkout [hash] [files]</code></p>
<p>It&#8217;s just that when you don&#8217;t specify the hash, it assumes HEAD.</p>
<p>If you&#8217;ve got changes you want to just throw away permanently, you can just reset:</p>
<p><code>git reset --hard</code></p>
<p>But reset is a powerful command that can also take you back in time. Let&#8217;s say you messed up the last commit, you can take yourself back to the way things were right before you comitted:</p>
<p><code>git reset HEAD^</code></p>
<p>Notice I didn&#8217;t use <code>--hard</code> because that throws away the changes. Instead, this form of the command throws away the commit by taking you to HEAD^ (one commit before HEAD), but it leaves the changes in your working tree. If you want the changes also to be left in your index (ready to be comitted) you can use</p>
<p><code>git reset --soft HEAD^</code></p>
<p>If you&#8217;re working on something and you decide you want to scrap it or work on it later</p>
<p><code>git stash</code></p>
<p>There are lots of fun things you can do with stashes but they&#8217;ve been covered on other blogs.</p>
<p><b>on merging&#8230;</b></p>
<p>If you&#8217;ve done a <code>git merge</code> and have some conflicts, launch <code>git mergetool</code> which will take you through the conflicted files one by one using your default merging tool (FileMerge, usually, on OSX) and let you merge them. However be careful. Either because of a misconfig on my end or some other quirk, FileMerge shows the file I pulled from svn as &#8220;LOCAL&#8221; while my file with changes is &#8220;REMOTE&#8221; which is counterintuitive to me and caused me to fubar a merge the first time I tried.</p>
<p>Take note that after the merge, you will have files ending with <code>.orig</code> left on your system so you&#8217;ll have to manually delete them, unless you have the config <code>mergetool.<tool>.keepBackup</code> set, but I haven&#8217;t tried this yet. Also, after the merge I was getting error messages about having a <code>.git/MERGE_HEAD</code> file, which I couldn&#8217;t find enough docs online for, so I just deleted it..and hopefully that did not fubar me.</p>
<p>Well that&#8217;s all for now. More might come as I learn to stop worrying and love the git.</p>
<p>P.P.S Many of these commands are not necessary if you use <a href="http://gitorious.org/projects/git-tmbundle">The Git Textmate Bundle</a> and <a href="http://github.com/Caged/gitnub/wikis/home">GitNub</a> which integrate together and work very well!</p>
<div class="plus-one-wrap"><g:plusone href="http://yanpritzker.com/2008/04/22/useful-git-commands-and-quirks/"></g:plusone></div>]]></content:encoded>
			<wfw:commentRss>http://yanpritzker.com/2008/04/22/useful-git-commands-and-quirks/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

