I have a bash script which accepts a string of either a branch name (e.g., \"master\", or \"feature/foo\") or a commit hash (e.g. \"1234abcd\").
I have the repository c
Imo you can't check this reliably, since a hash is also a valid branch name. Try:
git checkout -b 0c8158f47d7dda89226d4e816fee1fb9ac6c1204
This means there can be a situation where a branch with that name exists but also a commit.
Since you can pass a branch name or a commit to most of the git commands, you don't need to differentiate between them.