Skip to content

Instantly share code, notes, and snippets.

@elliotthilaire
Last active January 12, 2019 05:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elliotthilaire/d90f2ed0107b3a9791b08ee4da276783 to your computer and use it in GitHub Desktop.
Save elliotthilaire/d90f2ed0107b3a9791b08ee4da276783 to your computer and use it in GitHub Desktop.
A bash script to run a command against different branches or commits automatically
#!/bin/bash
# Usage:
# ./compare-branches.sh "./some-command arg-1 arg-2" branch-1 branch-2
#
# https://twitter.com/elliotthilaire/status/1083859808086720512
# Thanks to @schneems, @tosbourn, and @matthewrudy for their input.
current_branch=$(git symbolic-ref --short HEAD)
command=$1
commits=${@:2}
echo "running $command on $commits"
echo "----------------------------------------"
for commit in $commits
do
$(git checkout $commit)
eval $command
echo "----------------------------------------"
done
$(git checkout $current_branch)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment