1

I'm writing a shell script (zsh) that will run git commands for a set of directories. Some of these are projects with .rvmrc files which can take a while to run. When I cd into the directory to run a command, it activates the .rvmrc which really slows down the script quite a bit.

Example command: $(cd $dir && exec git branch)

I would like to either run the commands without cding into the directory in my script, or temporarily deactivate the .rvmrc file so cding into the directory does not run the rvmrc.

Any thoughts?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Brandon
  • 1,956
  • 18
  • 18
  • Possible duplicate of [git pull while not in a git directory](http://stackoverflow.com/questions/5083224/git-pull-while-not-in-a-git-directory) – Trevor Boyd Smith Mar 22 '17 at 18:09
  • The proposed duplicate ('git pull while not in a git directory') seems to cover the same ground as the accepted (only) answer, but it isn't entirely clear how/why that evades the problems with Ruby's version manager (which is what `.rmvrc` files relate to, it seems). – Jonathan Leffler Mar 22 '17 at 18:59

1 Answers1

7

you can specify the git working directory and .git location:

git --work-tree=$dir --git-dir=$dir/.git branch
git -C $dir branch

There are also environmental parameter available, please check the manuals

Mykola Gurov
  • 8,517
  • 4
  • 29
  • 27