For about a month now I've been sending weekly "Protip" emails about Git to the rest of engineering here at <ahref="http://slide.com">Slide</a>. I've been using them to slowly and casually introduce some of the more "interesting" features Git has to offer as we move away from Subversion entirely. Below is the first Protip I sent around, I'll be sure to send the rest in good time.
<br>
<hr/><br>
<br/><br>
<p><br>
Given the nature of how Git is structured, in that your "working copy" is also your "repository" you might find yourself switching branches relatively often. While you can actually switch branches with uncommited changes outstanding in your Git directory, it's not advised (as you might forget you're commiting changes in the wrong branch, etc). You have two options if you are halfway through some work, one is to commit a checkpoint revision, but the other is to make use of the <code>git stash</code> command.
<br>
</p><br>
A scenario where this becomes especially useful would be: Bill is working in his local branch "wip-funtime" on replacing large swaths of unnecessary useless code and Ted accidentally pushes some of Bill's other changes from another branch live and things <em>break</em>. Bill <em>could</em> commit his code and write a fairly uninformative log message like "checkpoint" which cheapens the value of the revision history of his changes <strong>or</strong> Bill can use <code>git stash</code> to snapshot his currently working state and context switch. In this case Bill would execute the following commands: <ul><br>
After performing the <code>git stash pop</code> command, Bill's Git repository will be in the exact same state, all his uncommitted changes in tact, as it was when he originally stashed and context-switched.
<br>
<p/><br>
For specific usage of `git stash` refer to the <ahref="http://www.kernel.org/pub/software/scm/git/docs/git-stash.html"target="_top">git stash man page</a><br>
<p/><br>
<p/><br>
<h3><aname="Example_usage_of_git_stash"></a><aname="Example_usage_of_git_stash_"></a> Example usage of `git stash` </h3><br>
# (use "git add <file>..." to update what will be committed)
<br>
#
<br>
# modified: db/dbroot.py
<br>
# modified: gogreen/coro.py
<br>
# modified: py/bin/_makepyrelease.py
<br>
# modified: py/initpkg.py
<br>
# modified: py/misc/_dist.py
<br>
# modified: py/misc/testing/test_initpkg.py
<br>
# modified: py/path/local/local.py
<br>
# modified: py/test/terminal/terminal.py
<br>
tyler@starfruit:~/source/git/main/bt>
<br>
</code><br>
<hr/><br>
<em>Did you know!</em><ahref="http://www.slide.com/static/jobs">Slide is hiring</a>! Looking for talented engineers to write some good Python and/or JavaScript, feel free to contact me at tyler[at]<ahref="http://slide.com">slide</a>