Skip to content

Instantly share code, notes, and snippets.

function find_git_branch {
local dir=. head
until [ "$dir" -ef / ]; do
if [ -f "$dir/.git/HEAD" ]; then
head=$(< "$dir/.git/HEAD")
if [[ $head == ref:\ refs/heads/* ]]; then
git_branch="[${head##*/}] "
elif [[ $head != '' ]]; then
git_branch='[detached] '