When I do this:

cd /home/erelsgl/git/erel-sites;  git commit -m "test"

I get correctly:

On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean

But, when I put the same line in the crontab of my account, I see in the logfile:

*** Please tell me who you are.


  git config --global user.email "you@example.com"
  git config --global user.name "Your Name"

to set your account's default identity.
Omit --global to set the identity only in this repository.

fatal: unable to auto-detect email address (got 'erelsgl@erelsgl-computer')

I put "whoami" in the crontab and got the same answer as outside ("erelsgl").

I also tried to put the recommended "git config --global" commands inside the crontab (I already ran them successfully outside the crontab) but this did not help.

What should I do to commit from crontab?

  • Are you putting these commands in the cron table for your account, or root's, or some other user's? Presuming that it's in your cron table, try prefixing the command with export GIT_DIR=/home/erelsgl; .
    – DopeGhoti
    Aug 16, 2016 at 7:42
  • @DopeGhoti I get an error "fatal: Not a git repository: '/home/erelsg‌​l". I also tried "export GIT_DIR=/home/erelsg‌​l/git", "export GIT_DIR=/home/erelsg‌​l/git/erel-sites" and "export GIT_DIR=/home/erelsg‌​l/git/erel-sites/.git", and got similar errors. Aug 16, 2016 at 8:50
  • Does it work if you just set them explicitly? I mean like this: cd /home/erelsgl/git/erel-sites; git commit -c user.email=you@email.com -c user.name=erelsgl -m "test"
    – terdon
    Aug 16, 2016 at 11:12
  • @terdon I am not sure what it does, but I get an error "fatal: Option -m cannot be combined with -c/-C/-F/--fixup.". Aug 16, 2016 at 13:21
  • How are you adding this to cron? Via /etc/crontab or crontab -e? If via /etc/crontab, you probably also need to set $HOME. Aug 19, 2016 at 13:33

2 Answers 2


git needs to find user.email and user.name in one of its config files or in environment variables. You have more options to make git get these values. Obviusly git does not use some of the config files when called from crontab.

I would recommend you to choose from two options:

1. Put user.email and user.name into the repository's config with commands

git config user.email "you@example.com"
git config user.name "Your Name"

You should be in the repository when doing this. In that way, the repository config file .git/config will have the values set and the commit should work from crontab. You can check with

cat .git/config

2. Set the environment variables to help git get the missing values. In that case I would run the commands like this

cd /home/erelsgl/git/erel-sites; GIT_COMMITTER_NAME="Your Name" GIT_COMMITTER_EMAIL="you@example.com" git commit -m "test"

I think the variables GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL should also work.

I have found this information on the following pages:

  • Thanks. This is probably the best solution in a multi-user system. Aug 22, 2016 at 3:55

Instead of --global, try --system

sudo git config --system user.email "you@example.com"
sudo git config --system user.name "Your Name"
  • But your answer still uses --global?
    – edwinksl
    Aug 19, 2016 at 14:55
  • Obviously I'd get something wrong. Actually replace --global by --system in the long snippet. I don't have edit privileges for my answer.
    – jswetzen
    Aug 19, 2016 at 14:56
  • You do have edit privileges for your own answer.
    – edwinksl
    Aug 19, 2016 at 14:57
  • I didn't see the link at first, maybe because it was just posted. Now it's fixed.
    – jswetzen
    Aug 19, 2016 at 14:58
  • This works! But it must be run with "sudo" Aug 19, 2016 at 15:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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