Skip to content

Instantly share code, notes, and snippets.

@Merovex
Last active April 2, 2017 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Merovex/597c68e5ce6f72870c891ab7d50ee5d9 to your computer and use it in GitHub Desktop.
Save Merovex/597c68e5ce6f72870c891ab7d50ee5d9 to your computer and use it in GitHub Desktop.
Auto Commit Git repo to GitHub
#!/bin/ruby
File.read("/PATH-TO/.auto-commit").split("\n").each do |dir|
Dir.chdir(dir)
next if `find . -newer .last-mod`.split("\n").empty? # No change to file system
puts "### #{Time.new.strftime("%Y-%m-%d %H:%M:%S")} (#{dir}) ###"
`git pull origin $(git symbolic-ref HEAD | cut -d'/' -f3)`
`git add . -A`
puts `git commit -am "Auto-commit: #{Time.new.strftime("%Y-%m-%d %H:%M:%S")}"`
puts `git push origin $(git symbolic-ref HEAD | cut -d'/' -f3)` if (ARGV[0] == 'push') ? true : false
`touch .last-mod`
end
@Merovex
Copy link
Author

Merovex commented Apr 2, 2017

*/5 * * * * ~/bin/git-commit.rb >> ~/Writing-Projects/writing-data/auto-push.log 2>&1
0 * * * * ~/bin/git-commit.rb push >> ~/Writing-Projects/writing-data/auto-push.log 2>&1

I have it so that Root's .ssh config points to my GitHub credentials

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment