Hacker News new | ask | show | jobs
by nu11p01n73R 3184 days ago
> git config --global alias.git '!exec git'

Is the exec really required?

   git config --global alias.git '!git'
Will also work. Am I missing something?

EDIT: From git doc, "If the alias expansion is prefixed with an exclamation point, it will be treated as a shell command"

So exec is not required then.

2 comments

You are right, I checked and the resulting sub-process tree is the same regardless of whether !git or !exec git is used.

Also, I found one caveat from the same docs:

> Note that shell commands will be executed from the top-level directory of a repository, which may not necessarily be the current directory. GIT_PREFIX is set as returned by running git rev-parse --show-prefix from the original current directory.

So, if I have a modified file `bar` in subdirectory `foo` under project root, and I am currently in `foo`, git status will show:

    modified:   bar
but git git status will show:

    modified:   foo/bar
To fix this, we should use cd first:

    git config --global alias.git '!cd "$GIT_PREFIX" && git'
I don't think you are missing anything, good catch.