Check if commit is first commit in pre-commit hook

Currently I’m using the pre-commit hook to disallow committing to the master branch (forces me to work on other branches and merge in changes). This doesn’t allow me to do an initial commit on a newly created repo. I want to add a check to allow a commit on master if it’s the first commit.

I’ve tried multiple versions of this with no luck…

if [[ `git shortlog | grep -E '^[ ]+\w+' | wc -l | tr -d ' '` == 0 -a `git symbolic-ref HEAD` == "refs/heads/master" ]]
    echo "You cannot commit in master!"
    echo "Stash your changes and apply them to another branch"
    echo "git stash"
    echo "git checkout branch"
    echo "git stash apply"
    exit 1

Git Baby is a git and github fan, let's start git clone.