dotfiles - faster commit messages

I use dotfiles to speed up my workflow. I recently threw together this script to speed up writing my git commit messages.

It auto adds the branch name to your commits.

So, instead of this:

git commit -m "[name of ticket] here is my commit message"

I can now type this:

git-commit "here is my commit message"

This is awesome because now I can spend time doing things other than typing.

Learn more about dotfiles here.

Here’s the code:

#!/usr/bin/env ruby

# git-commit. Script for speeding up writing commit msg's.
# Adds branch name to beginning of commit message if on any branch other than master.

# Options:
# -s for appending [ci skip] to msg

branch = `git rev-parse --abbrev-ref HEAD`.gsub("\n",'')
skip, commit_msg = ""

if ARGV[0] == '-s'
  ARGV.shift
  skip = " [ci skip]"
end

branch = (branch == "master") ? "" : "[#{branch}] "
commit_msg = "#{branch}#{ARGV.join('')}#{skip}"

command = "git commit -m \"#{commit_msg}\""

puts command
exec command