I have a git repository with multiple branches. The repository has a makefile which is identical between branches. I’d like to create a bash script that can be run on a regular basis that pulls all branches from the remote repository and then runs make for every branch that has changed, or been added. The executable created is then moved to another location on the server, and a make clean would be run before beginning on the next branch to be processed.
The order of commands I’d be running would be
make
cp executable /some/other/directory/branch_name
make clean
Is this even possible to do with a shell script, if it is how could I go about implementing this. If a shell script is ill suited to this task, how else can I go about achieving the same result?
I’d do something like this:
The nice thing about fetching first is that you don’t have to unnecessarily check out branches with no changes; if your repo is big this can be a time-saver.
Obviously there are choices to be made about handling errors; I just went with the simplest thing that still made sense. For more complex handling, you might instead want to do things of the form
if make; then ...; else ...; fi, e.g.: