I'm trying to automate my workplace as much as I can, but I'm kind of new to bash scripts. What is the best way to tell bash script to run git co master and if it is successful do git pull and once it is finished do some other commands? I need to do this every morning at 7am (can I schedule it directly in bash script?)


You can string together commands using && so:

git co master && git pull && some_other_commands

To schedule, use cron if you are on Mac OS X or Unix/Linux.

The crontab entry would be:

* 7 * * * /path/to/your/bash/script
  • You could also check variable $? after running the command in an if statement to determine if it run successfully. – Alex Nov 14 '13 at 20:29
  • Additionally, you might want to use git stash to preserve changes to the local repo that haven't been checked in yet. – Roland Smith Nov 16 '13 at 23:52

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.