Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ $ brew install git-extras
- `git unlock`
- `git reset-file`
- `git pr`
- `git root`

## git-extras

Expand Down Expand Up @@ -694,3 +695,14 @@ From https://github.com/tj/git-extras
* [new ref] refs/pulls/226/head -> pr/226
Switched to branch 'pr/226'
```

## git-root

show the path to root directory of git repo

```bash
$ pwd
.../very-deep-from-root-directory
$ cd `git root`
$ git add . && git commit
```
24 changes: 24 additions & 0 deletions bin/git-root
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh

git_root() {
git rev-parse --show-toplevel
}

# get the relative path of current path according to root of repo
git_root_relative() {
git rev-parse --show-prefix
}

if test $# -eq 0; then
git_root
else
case "$1" in
-r|--relative)
git_root_relative
;;
*)
git_root
;;
esac
fi

45 changes: 45 additions & 0 deletions man/git-root.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
.\" generated with Ronn/v0.7.3
.\" http://github.com/rtomayko/ronn/tree/0.7.3
.
.TH "GIT\-ROOT" "1" "November 2014" "" ""
.
.SH "NAME"
\fBgit\-root\fR \- show path of root
.
.SH "SYNOPSIS"
\fBgit root\fR \fIOPTIONS\fR
.
.SH "DESCRIPTION"
print the path for the root directory of git repo
.
.SH "OPTIONS"
\-r, \-\-relative
.
.P
show the relative path from root directory to current directory
.
.SH "EXAMPLES"
.
.nf

$ cd \.\.\./git\-extras/bin
$ git root \-r
bin/
$ git root
/home/\.\.\./git\-extras
$ cd `git root`
$ pwd
/home/\.\.\./git\-extras
# then we can
$ git add \. && git commit
.
.fi
.
.SH "AUTHOR"
Written by spacewander <\fIspacewanderlzx@gmail\.com\fR>
.
.SH "REPORTING BUGS"
<\fIhttps://github\.com/tj/git\-extras/issues\fR>
.
.SH "SEE ALSO"
<\fIhttps://github\.com/tj/git\-extras\fR>
126 changes: 126 additions & 0 deletions man/git-root.html

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 42 additions & 0 deletions man/git-root.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
git-root(1) -- show path of root
========================================

## SYNOPSIS

`git root` [OPTIONS]

## DESCRIPTION

print the path for the root directory of git repo

## OPTIONS

-r, --relative

show the relative path from root directory to current directory

## EXAMPLES


$ cd .../git-extras/bin
$ git root -r
bin/
$ git root
/home/.../git-extras
$ cd `git root`
$ pwd
/home/.../git-extras
# then we can
$ git add . && git commit

## AUTHOR

Written by spacewander &lt;<[email protected]>&gt;

## REPORTING BUGS

&lt;<https://github.com/tj/git-extras/issues>&gt;

## SEE ALSO

&lt;<https://github.com/tj/git-extras>&gt;