Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 11631

How to tell a Git branch name from commit hash?

$
0
0

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 checked out, so I can call Git.

What is the best way to determine whether the string is a branch name or a commit hash?

#!/bin/bashcommit_or_branch="$1"cd /path/to/my_repogit fetchif <is_branch $commit_or_branch>then    echo "it's a branch"else    echo "it's a commit"fi

Viewing all articles
Browse latest Browse all 11631

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>