I'm trying to use git push in a bash script being run by crontab to push a commit to github. At the end of the script I'm doing this:

# script processes some files, then:
git add -A
git commit -a -m "Updated $(date)"
git push origin master

The add and commit work fine (and the push works fine when running the script from the CL, not using cron), but I get errors on the push to github with cron:

git: 'credential-osxkeychain' is not a git command. See 'git --help'.
fatal: could not read Username for 'https://github.com': Device not configured

I've searched through other threads (like this, and this), but it doesn't appear to be an issue with SSH (at least I tried passing SSH_AUTH_SOCK environment variable in the crontab line and that didn't work). Running OSX 10.8.

Any ideas?

1 Answer 1


TL;DR: Solved problems with git push via cron by using SSH instead of HTTPS.

Thanks to the support team at GitHub I was able to solve this.

The first problem was that git-credential-osxkeychain was not in my path when the cron job ran. For me, git and git-credential-osxkeychain were both being run out of the Xcode command line tools directory:

$ which git
$ which git-credential-osxkeychain

When running which git from cron, turns out cron was running git from /usr/bin.

I added the appropriate directory to my PATH at the top of the cron job with:

export PATH=$PATH:/Applications/Xcode.app/Contents/Developer/usr/bin

That solved the git: 'credential-osxkeychain' is not a git command error, but I got yet another error:

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

At the suggestion of the GitHub support team, I solved the problem (without the need for git-credential-osxkeychain at all) by authenticating via SSH instead of https:

git remote set-url origin [email protected]:username/repo.git
  • Thanks! Same thing worked for me with bitbucket. Commented Jul 15, 2019 at 8:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .