Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

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
/Applications/Xcode.app/Contents/Developer/usr/bin/git
$ which git-credential-osxkeychain
/Applications/Xcode.app/Contents/Developer/usr/bin/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 git@github.com:username/repo.git

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.