Last Updated: February 25, 2016
·
2.349K
· fuadsaud

cd to git root

Ever been browsing around your git repo and wanted to quickly get back to your root? I use this function to teleport instantly:

function cd_git_root {
  dir='.'
  while [ ! -d "$dir/.git" ]; do
    [ $(readlink -m $dir) = '/' ] && return
    dir="../$dir"
  done

  cd $dir
}

2 Responses
Add your response

Faster and easier is

cd $(git rev-parse --show-toplevel)
over 1 year ago ·

ahn, didn't know that one. thanks!

over 1 year ago ·