Crontab GitHub push won't recognize credentials

Viewed 119

I have a crontab script to push some files to git. I use github desktop and it created my directory on my M1 MacOs computer.
Shell Script:

#!/bin/sh
cd /Users/me/Documents/GitHub/myUsername.github.io
git add -A
git commit -m "Daily update."
git push

The script works just fine when I run it from terminal but when I run it via chron I get the message

fatal: could not read Username for 'https://github.com': Device not configured

How can I run this from crontab and have it successfully push?

1 Answers

Check if the process runs as root from cron.

If so, it would not access the same git config --global credential.helper setting (which is set in /home/myuser, not /root)

Make sure your crontab file uses the username field in order to execute the command as you, not as root.

The OP confirms:

  • the process is runs as the user account
  • there is no credential helper.

Recommendation:

  • install GCM, the cross-platform Git Credential Manager from Microsoft
  • register your github.com credentials (GitHub user account / token)

That is:

printf "host=github.com\nprotcol=https\nusername=MyGitHubAccount\npassword=myGitHubToken" | git credential-manager-core store

This assumes the git-credential-manager-core executable installed with GCM is in your $PATH.

That way, no more "could not read Username" on the next git push.


The OP Sparkles adds in the comments:

It turned out I do think homebrew was affecting things because after getting rid of it it all seemed to work.

Related