« Back to Index

Simple check for git repo in Bash

View original Gist on GitHub

simple-git-repo-check.bash

function git_environment() {
  $(git rev-parse --is-inside-work-tree >& /dev/null)

  if [ "$?" -eq "128" ]; then
    git_branch=""
  else
    git_branch=" ($(git branch | grep '^*' | cut -d ' ' -f 2))"
  fi
}

echo $git_branch