Andrew Scripts

Musings about Programming and Programmer Life-Skills

Category: Git

Smarter-Git: My Rakefile of Automated Awesomeness

Smarter Git

I created this rakefile of git tasks back when I was working with a dev team that relied heavily on rake. My reasoning was that since I was already doing rake deploy:staging and the like all the time (they preferred Screwcap to Capistrano), I might as well do rake git:merge_and_deploy too. This works especially well with a text expander or bash alias, where you can setup rg: to expand to rake git: or rug: to become rake username:git: if you want to further namespace out these functions.

The tools I use here also work well by themselves or in their own aliases. Use this collection as a starting point for further customizing your workflow, or use as is for a quick but complete solution.

Here are the libraries I used in this rakefile:

  • Legit – Provides a handy ‘sprout’ function for new branch creation
  • Git Smart – Provides smart-merge, smart-pull, and smart-log
  • Git Extras

Awesome Git helpers: Git-Smart, Legit, Extras, etc.

Links to some amazing Git helpers and things.

Git-Smart and Legit have good install instructions. Here’s how to install the other scripts (which are all just shell scripts compatible with bash, zsh, probably others):

  1. Copy the raw script into a file, and put that file in a folder that’s in your $PATH (I use /usr/local/bin).
  2. Restart your terminal or source your .bashrc file.
  3. Profit! (Or, at least, enjoy your new scripts)

Git Extras and Git Utils can both be installed using Brew as well:

brew install git-extras git-utils

See changes between commits in Git

Github has an awesome feature that allows you to see a visual diff log of all of the changes between two commits. Learned how to do it on the command line today.

Here’s how to see the changes you’ve made in your repo between two commits (from the official Git docs):

git diff OLDER_COMMIT NEWER_COMMIT

Technically, you can use this to compare branches and tags too. Here’s a handy shortcut for comparing your most recent commit with the commit right before it:

git diff HEAD^ HEAD

Especially handy if, like me, you forgot what you just finished working on (or, more likely, if you haven’t worked on something for a couple days/weeks).

%d bloggers like this: