Skip to content

Instantly share code, notes, and snippets.

@Merovex Merovex/auto-commit.rb
Last active Apr 2, 2017

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner 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
You can’t perform that action at this time.