forked from Dieterbe/git-scripts
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgit-root
More file actions
Latest commit
executable file
·14 lines (14 loc) · 408 Bytes
/
Copy pathgit-root
File metadata and controls
executable file
·14 lines (14 loc) · 408 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#!/bin/sh -e
# inspired by http://stackoverflow.com/questions/957928/is-there-a-way-to-get-to-the-git-root-directory-in-one-command/3009378#3009378
# gives absolute path to git repository root, either for cwd, or directory (or files' dirname) given as $1
# when not a git repository, exit >0
if [ -n"$1" ]
then
if [ -d"$1" ]
then
cd$1
else
cd`dirname $1`
fi
fi
exec git rev-parse --show-toplevel