Skip to content

Commit 9074608

Browse files
committed
Merge pull request #273 from spacewander/master
'git root' shows the path to root of repo.
2 parents 1748fb2 + 92c34e8 commit 9074608

File tree

5 files changed

+249
-0
lines changed

5 files changed

+249
-0
lines changed

Readme.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ $ brew install git-extras
7373
- `git unlock`
7474
- `git reset-file`
7575
- `git pr`
76+
- `git root`
7677

7778
## git-extras
7879

@@ -694,3 +695,14 @@ From https://github.com/tj/git-extras
694695
* [new ref] refs/pulls/226/head -> pr/226
695696
Switched to branch 'pr/226'
696697
```
698+
699+
## git-root
700+
701+
show the path to root directory of git repo
702+
703+
```bash
704+
$ pwd
705+
.../very-deep-from-root-directory
706+
$ cd `git root`
707+
$ git add . && git commit
708+
```

bin/git-root

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/sh
2+
3+
git_root() {
4+
git rev-parse --show-toplevel
5+
}
6+
7+
# get the relative path of current path according to root of repo
8+
git_root_relative() {
9+
git rev-parse --show-prefix
10+
}
11+
12+
if test $# -eq 0; then
13+
git_root
14+
else
15+
case "$1" in
16+
-r|--relative)
17+
git_root_relative
18+
;;
19+
*)
20+
git_root
21+
;;
22+
esac
23+
fi
24+

man/git-root.1

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
.\" generated with Ronn/v0.7.3
2+
.\" http://github.com/rtomayko/ronn/tree/0.7.3
3+
.
4+
.TH "GIT\-ROOT" "1" "November 2014" "" ""
5+
.
6+
.SH "NAME"
7+
\fBgit\-root\fR \- show path of root
8+
.
9+
.SH "SYNOPSIS"
10+
\fBgit root\fR \fIOPTIONS\fR
11+
.
12+
.SH "DESCRIPTION"
13+
print the path for the root directory of git repo
14+
.
15+
.SH "OPTIONS"
16+
\-r, \-\-relative
17+
.
18+
.P
19+
show the relative path from root directory to current directory
20+
.
21+
.SH "EXAMPLES"
22+
.
23+
.nf
24+
25+
$ cd \.\.\./git\-extras/bin
26+
$ git root \-r
27+
bin/
28+
$ git root
29+
/home/\.\.\./git\-extras
30+
$ cd `git root`
31+
$ pwd
32+
/home/\.\.\./git\-extras
33+
# then we can
34+
$ git add \. && git commit
35+
.
36+
.fi
37+
.
38+
.SH "AUTHOR"
39+
Written by spacewander <\fIspacewanderlzx@gmail\.com\fR>
40+
.
41+
.SH "REPORTING BUGS"
42+
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
43+
.
44+
.SH "SEE ALSO"
45+
<\fIhttps://github\.com/tj/git\-extras\fR>

man/git-root.html

Lines changed: 126 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/git-root.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
git-root(1) -- show path of root
2+
========================================
3+
4+
## SYNOPSIS
5+
6+
`git root` [OPTIONS]
7+
8+
## DESCRIPTION
9+
10+
print the path for the root directory of git repo
11+
12+
## OPTIONS
13+
14+
-r, --relative
15+
16+
show the relative path from root directory to current directory
17+
18+
## EXAMPLES
19+
20+
21+
$ cd .../git-extras/bin
22+
$ git root -r
23+
bin/
24+
$ git root
25+
/home/.../git-extras
26+
$ cd `git root`
27+
$ pwd
28+
/home/.../git-extras
29+
# then we can
30+
$ git add . && git commit
31+
32+
## AUTHOR
33+
34+
Written by spacewander &lt;<[email protected]>&gt;
35+
36+
## REPORTING BUGS
37+
38+
&lt;<https://github.com/tj/git-extras/issues>&gt;
39+
40+
## SEE ALSO
41+
42+
&lt;<https://github.com/tj/git-extras>&gt;

0 commit comments

Comments
 (0)