DEV Community

Discussion on: How to Get the Git Directory

Collapse
 
phallstrom profile image
Philip Hallstrom

I'd tweak that command to git rev-parse --show-toplevel 2> /dev/null so that if you're not in a git repo it doesn't spit a warning to the console.

ruby foo.rb
fatal: Not a git repository (or any of the parent directories): .git
nil

vs

ruby foo.rb
nil
Collapse
 
burdettelamar profile image
Burdette Lamar

There's no /dev/null on Windows. But I think Open3.popen3 would work.