How to Check if the Current Directory is a Git Repository

Use this command in your Terminal to determine if the directory you are currently in is a Git repository or not:

git rev-parse --is-inside-work-tree

The shell prints true if you are in a git repository’s working tree. It prints false if you are inside the ‘.git’ tree but not the working directory, and it prints a fatal error if it’s neither (not connected to any git repo).

Both ‘true’ and ‘false’ are printed on STDOUT with an exit status of 0, the fatal error is printed on STDERR with an exit status of 128.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s