Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Script getting git working directory root? [duplicate]

Tags:

git

linux

bash

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.

like image 763
Andrew Tomazos Avatar asked Dec 11 '22 23:12

Andrew Tomazos


1 Answers

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
like image 64
Tech163 Avatar answered Dec 14 '22 11:12

Tech163