Created
November 4, 2012 15:31
-
-
Save JohnLockwood/4012307 to your computer and use it in GitHub Desktop.
Some Rake Tasks to Automate Common Git Tasks -- I use this at johnlockwood.com.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Use rake --tasks | grep git for a list | |
# The most useful is rake git:checkin, which is essentially add + commit + message + push. | |
namespace :git do | |
desc "Run ssh-add to enter password for your ssh key a single time" | |
task :setup do | |
sh "ssh-add" | |
end | |
desc "Stage any deleted files to prepare for commit" | |
task :delete do | |
sh "git ls-files --deleted -z | xargs -0 git rm" | |
end | |
desc "Add files, commit them, push them" | |
task :checkin do | |
do_checkin | |
end | |
desc "Add / commit / push the wiki" | |
task :checkin_wiki do | |
chdir "wiki" | |
do_checkin | |
chdir ".." | |
end | |
desc "Tests showing argument" | |
task :show_arg, [:param1] do |t, args| | |
puts "Param1 is: #{args.param1}" | |
end | |
desc "Git Status" | |
task :status do | |
sh "git status" | |
chdir "wiki" | |
sh "git status" | |
end | |
def do_checkin | |
print "Enter commit message to add, commit and push files, or blank to quit:\n" | |
commit_message = STDIN.gets.chomp | |
if commit_message.nil? | |
print "Commit and push aborted at user request." | |
return | |
end | |
sh "git add ." | |
sh "git commit -m\"#{commit_message}\"" | |
sh "git push" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment