That code is almost correct for the initial setup of your repository, there's a few more steps you need to add to the end:
git branch -M main
git remote add origin [email protected]:username/repository-name.git #Edit this to match your Github repo
git push -u origin main
The first line I've added sets the branch on git (Github default branch is main
), the second line sets the remote origin, and the final line pushes your folder to Github.
The script you call from crontab should look like this:
cd ~/myfolder
git add .
git commit -a -m "$current_date"
git push
Assuming you named it upload-script.sh
, this is the crontab entry, which will run at every minute (the fastest interval crontab allows) with no output:
* * * * * ~/upload-script.sh >/dev/null 2>&1
I'm not sure if you can ger rate-limited by Github for this, so you might need to decrease the speed of pushes. You can generate crontab entries using crontab generator if this is the case.
And for reference, here's Github's documentation on how to set up a remote repository (helpful for debugging git issues):
https://docs.github.com/en/get-started/using-git/pushing-commits-to-a-remote-repository
Hope this helps :)