Possible Duplicate:
Is there a way to get the git root directory in one command?
I am writing a bash script (actually a Makefile) that needs to use an argument that is a directory relative to the root of the git working directory that contains the current directory.
That is:
/home/me$ git clone /abc/foo.git
directory foo created
/home/me$ cd foo/bar
/home/me/foo/bar$ execute_script.sh
hello /home/me/foo/baz
execute_script.sh is as follows:
echo hello `git something`/baz
What is git something ? It should return the absolute path of the current git working root.
Well, if you know you're going to be in the bar folder, you can try:
echo hello `pwd`/../baz
Edit: As @Andrew Tomazos pointed out earlier to a different thread, you can do
echo hello `git rev-parse --show-toplevel`/baz
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With