DEV Community

HaxNet
HaxNet

Posted on

Git Auto Push

I am no coder or programmer by any means. I just got my new PC and installed Vanilla Arch Linux on it and already customized it 90% to how I like my PC to be.

I use github to store working documents: I love that it has basically unlimited storage. One thing I was trying to figure out was that I am always creating new files or working on existing files.

Manually typing out all the commands in the terminal is a bit cumbersome and tiring.

I did a little research and figured out to just manually create a script that will auto push by using crontab.

First, create a script. I named it auto_push.sh

#!/bin/bash

while true; do

cd /path/to/your/directory/
git add -A # this basically add all new files and/or tracked files that has been changed
git commit -m "Auto-updates: $(date)" # this puts the timestamp
git push
sleep 30 # Pauses the script for 30 seconds before the next iteration. Adjust this number to change the frequency of checks

done
Enter fullscreen mode Exit fullscreen mode

Second, make sure you have crontab enabled in your system. If you don't have it, just download it from the AUR (I am using archlinux) you want to install cronie

you need to start the service and enable it on startup. type this in the terminal

sudo systemctl enable cronie.service
sudo systemctl start cronie.service
Enter fullscreen mode Exit fullscreen mode

now in the terminal type

crontab -e

this will open up your choice of editor, mine is vim.

in the file, put this in the line

*/5 * * * * /absolute/path/to/your/script/auto_push.sh
this code means that it will run every 5 minutes.

that's it.

Top comments (3)

Collapse
 
lovelindhoni profile image
Lovelin

systemd timers are better xD

Collapse
 
haxnet profile image
HaxNet

I never ran any schedulers before so it was really new to me since it was something I just thought I needed to figure out.

I am definitely going to take a look at systemd timers. Thanks!

Collapse
 
otumianempire profile image
Michael Otu • Edited

awesome... but any reason the 30sec sleep?

sleep 30 # Pauses the script for 30 seconds before the next iteration.