Search code examples
gitshellterminalparentcd

How to browse back (cd ..) to parent until find a specific folder?


I'm often browsing deep in my Git repository folder structure via terminal and I would like to navigate back until reach the root folder who contain the .git folder.

For example:

cd ./a/b/c/d/e/f/g/h/i

In order to return back to the a folder parent, the Git local repository root I would need to execute:

cd ../../../../../../../../..

How would I be able to return to the root folder without many ../?


Solution

  • You can do it with the following command:

    cd `git rev-parse --show-toplevel`
    

    Thanks to jthill for the updated version.