Hey I am trying to push code to git using a cron job on the Mac. I edit my crontab using crontab -e
and have the following inside:
* 12 * * 1 ~/Dropbox/MD/sync.sh
* 12 * * 5 ~/Dropbox/MD/sync.sh
The script is as follows:
#!/bin/bash
cd ~/Dropbox/MD
/usr/bin/git add .
/usr/bin/git commit -m "Docs auto update"
/usr/bin/git push origin master
However the command fails and when I run mail
I can check the error message which is: fatal: could not read Username for 'https://github.com': Device not configured
. How can I fix this issue? If I run the commands manually from the terminal I have no issues and I am not prompted for user credentials.
Any pointers on this would be much appreciated. Thanks!
When automating git tasks using SSH keys is recommended. You can setup SSH keys with push access by following these steps:
ssh-keygen -t rsa -b 4096 -C "[email protected]"
)cat ~/.ssh/id_rsa.pub
)Deploy Keys
(https://github.com/user/project/settings/keys)Allow write access
Add Key
Please note this will only work for repositories cloned with the following remote: [email protected]:user/project.git
The remote can be updated wit the following steps:
git remote remove origin
git remote add origin [email protected]/project.git