Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the path of the current directory relative to root of the git repository?

Tags:

git

bash

I've seen this question, which tells how to get the path of a particular file relative to the root of the git repo. But I now want to get the path of the current directory, not a specific file. If I use

git ls-tree --full-name --name-only HEAD .

I get the list of all the files in the directory.

Is this possible?

like image 998
ewok Avatar asked Oct 07 '16 17:10

ewok


People also ask

How do you display the path to the current directory git?

Use the terminal to display the . git directory with the command ls -a . The ls command lists the current directory contents and by default will not show hidden files.

What is the path of the repository root?

By default, the project repository is located under the root directory. The folder is named by the project's unique ID (GUID), and supports only local path drives (C:\) and UNC paths (such as \\system\Remote Repo).

How do I find my GitHub repository path?

On the GitHub website, click on you repository of interest. Locate the green button named Code and click on it. The GitHub URL will appear.

How do I get to the root directory in git bash?

Whenever inside a git repo and want to cd to its root, typing gitroot will take you to its root dir.


1 Answers

How about:

$ git rev-parse --show-prefix

From man git-rev-parse:

--show-prefix
           When the command is invoked from a subdirectory, show
           the path of the current directory relative to the top-level
           directory.
like image 83
Arkadiusz Drabczyk Avatar answered Sep 20 '22 08:09

Arkadiusz Drabczyk