0

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?)

1 Answer 1

1

You can string together commands using && so:

#!/bin/bash
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
2
  • You could also check variable $? after running the command in an if statement to determine if it run successfully.
    – Alex
    Nov 14, 2013 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. Nov 16, 2013 at 23:52

You must log in to answer this question.

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