Ataraxia Ataraxia - 1 year ago 155
Git Question

Check if directory is git repository (without having to cd into it)

What's a shell command I can use to, using the full directory path, determine whether or not a given directory is a git repository? Specifically, I'd like to be able to do this without being in the directory, and without having to cd into it. I'd also like to be able to do it with a command that returns a simple "true" or "false" (much the way that rev-parse --is-inside-work-tree does), but it's not a requirement.

Answer Source

Use git -C <path> rev-parse. It will return 0 if the directory at <path> is a git repository and an error code otherwise.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download