5

If I define a git alias that executes an external script is there any way to get the original CWD? I know external scripts always execute at the root of the repo so I was just wondering if there was an env variable or something I could use to figure out where I ran my script.

Here is an example alias:

git config --global alias.here '!echo pwd `pwd`'

/home/me/repo/folder$ git here
pwd /home/me/repo

I'm looking for something that does the following:

git config --global alias.here '!echo pwd $OLD_PWD'


/home/me/repo/folder$ git here
pwd /home/me/repo/folder
TimWolla
  • 31,849
  • 8
  • 63
  • 96
HaxElit
  • 3,983
  • 7
  • 34
  • 43

1 Answers1

8

As per the manual, you should be able to use GIT_PREFIX, which will be set with the same prefix as returned by git rev-parse --show-prefix. You can append that prefix to the root path.

http://schacon.github.com/git/git-config.html

manojlds
  • 290,304
  • 63
  • 469
  • 417
  • Do you know what version of git that was added in ? Apparently i'm on 1.7.1 which I think is outdated. Might have to manually install the update. – HaxElit Jan 27 '12 at 22:28
  • I had an outdated version of git. Apparently the version on ubuntu 10.10 is pretty old. Use the PPA to update to a newer version. – HaxElit Mar 26 '12 at 14:24
  • For anyone still stuck with Git 1.7.x, `GIT_PREFIX` was first added in Git 1.7.6. – torek May 06 '18 at 18:41