Leksat
Leksat

Reputation: 3071

Check if directory is a Git root in one command

I need

Upvotes: 5

Views: 2179

Answers (2)

gniourf_gniourf
gniourf_gniourf

Reputation: 46813

Using git-rev-parse is the way to go. Just make sure you compare it appropriately with PWD, and redirect standard error to /dev/null:

[[ $(git rev-parse --show-toplevel 2>/dev/null) = "$PWD" ]]

Upvotes: 6

Leksat
Leksat

Reputation: 3071

This works for me:

[ $(git rev-parse --show-toplevel) == $(pwd) ]

Upvotes: 2

Related Questions