Skip to content

Instantly share code, notes, and snippets.

@inscapist
Last active December 21, 2015 02:29
Show Gist options
  • Save inscapist/6235679 to your computer and use it in GitHub Desktop.
Save inscapist/6235679 to your computer and use it in GitHub Desktop.
a ruby script to simplify git tasks
export PATH=${PATH}:/Users/felixtioh/Development/adt-bundle/sdk/platform-tools:/Users/felixtioh/Development/adt-bundle/sdk/tools
export PATH=${PATH}:/Users/felixtioh/bin
#!/usr/bin/env ruby
require 'optparse'
options = {clean: false, push: false, origin: 'origin'}
OptionParser.new do |opts|
opts.banner = "Usage: gitpush [options]"
opts.on("-m", "--message MESSAGE", "Pass in commit message") do |v|
options[:message] = v
end
opts.on("-c", "--clean", "Clean cache") do
options[:clean] = true
end
opts.on("-p", "--push", "Push to origin") do
options[:push] = true
end
opts.on("-o", "--origin ORIGIN", "Change origin") do |v|
options[:origin] = v
end
end.parse!
system "git rm -rf --cached ." if options[:clean]
system "git add ."
system "git commit -m '#{options[:message]}'"
system "git push #{options[:origin]}" if options[:push]

#sample usage: gitpush -m 'commit without push'

gitpush -pm 'commit and push to origin'

gitpush -pm 'commit and push to specified origin' -o 'another_origin'

gitpush -cm 'clean cache, add, and push to origin'

#installation:

  • add executable to ~/bin
  • add ~/bin to $PATH
  • chmod u+x
  • chmod g+x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment