Last active
March 10, 2019 01:21
-
-
Save hilbix/7724772 to your computer and use it in GitHub Desktop.
`git exec` to exec command within GIT directory.
`git top` to exec on submodule top level directory (somewhat).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
git config --global alias.exec '!exec ' | |
git config --global alias.top '!f() { GIT_TOP="${GIT_DIR%%/.git/modules/*}"; [ ".$GIT_TOP" != ".$GIT_DIR" ] && cd "$GIT_TOP"; exec "$@"; }; f' | |
# THIS IS PUBLIC DOMAIN. | |
# | |
# `git exec` executes something in the current GIT module's base directory. `git exec pwd` gives this base. | |
# Stolen from http://stackoverflow.com/questions/957928/is-there-a-way-to-get-the-git-root-directory-in-one-command/957978#comment9747528_957978 | |
# | |
# `git top` is like `git exec`, but executes in the topmost GIT directory, even from within a GIT submodule. | |
# - needs /bin/bash as your shell | |
# - needs `GIT_DIR` is within the worktree | |
# - needs `.git`-Files for submodules like in recent GIT | |
# - does not work for bare repositories (of course) | |
# - softlinks are expanded as if you run `cd $(readlink -e .)` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For some reason
git
s apparently do not define$GIT_DIR
, so this is failing. For an update seehttps://github.com/hilbix/gitstart/blob/a7c22dd69a652b97f2cd64e697dc3b64413ab8ad/aliases.sh#L339 (git dir)
and
https://github.com/hilbix/gitstart/blob/a7c22dd69a652b97f2cd64e697dc3b64413ab8ad/aliases.sh#L326-L330 (git top)