Skip to content

Instantly share code, notes, and snippets.

@franzese
Created January 3, 2020 20:56
Show Gist options
  • Save franzese/eef732ebf9fdd68ceec91c644e00122a to your computer and use it in GitHub Desktop.
Save franzese/eef732ebf9fdd68ceec91c644e00122a to your computer and use it in GitHub Desktop.
Simple script to determine if current git repo is on master (or specified branch)
#!/bin/sh
# get the current branch name
branchName=$(git symbolic-ref --short HEAD)
# get the branch name to match from params
# if no params, use `master`
if [ "$1" != "" ]; then
masterBranch="$1"
else
masterBranch="master"
fi
# success if they match, error if not
if [ "$branchName" = "$masterBranch" ]; then
echo SUCCESS: You are on "$branchName"
exit 0
else
echo ERROR: You are not on "$masterBranch", you are on "$branchName"
exit 1
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment