How to get project root / git root from within the project

This simple trick allows to retrieve GIT_ROOT or PROJECT_ROOT from anywhere within the project folder structure. Whenever it’s needed, just use this:

export GIT_ROOT=$(realpath $(git rev-parse --git-dir)/..)
cd $GIT_ROOT;

Follow me: Facebooktwitterby feather
Share me: Facebooktwitterredditmailby feather