At least in version, it seems git does not like being run
from outside the repository, even if the file(s) being operated
on are inside the repository, unless it is given a pointer to the
repository via the --git-dir= option or the GIT_DIR enironment

For example, suppose /foo/bar is a local repository and baz.c is a
file in the outermost directory that I want to remove.  This works:

  $ cd /foo/bar
  $ git rm baz.c

but this, which intuitively should mean exactly the same thing,

  $ cd /foo
  $ git rm bar/baz.c
  fatal: Not a git repository (or any of the parent directories): .git

I've written a wrapper script that solves this problem, but it is
more an illustration or proof of concept than a real "solution"
-- the command line parsing may well be imperfect, and it would
be semantically incorrect in such cases as committing multiple
(individually specified) files:  it would do a separate commit
of each pathname rather than a single commit of all pathnames.

Has anyone considered enhancing the automatic repository search in
git itself to look in the directory where the specified file(s) is/are
located, as a last resort before failing?  (Yes, this does present
the potential for operating on multiple repositories with a single
invocation of git; would that be a bad thing?)



# smarter git:  if the current directory has no .git subdirectory
# (i.e. is not in a repository), try running git in the directory
# where each file is located instead of in the current directory.

[ "$1" == "--version" -o "$1" == "--help" -o "$1" == "--exec-path" \
  -o "x$GIT_DIR" != "x" -o -d .git ] && exec git "$@"

# Set defaults

# Collect flag params
while [[ "$1" == -?* ]] ; do
   case "$1" in
      --git-dir=* )
      * )
   flags="$flags $1"

[ "$dirSet" == "1" ] && exec git $flags "$@"

# next word must be the command


# remaining words must be pathnames

for f in "$@"
   ( cd $(dirname "$f") && git $flags $gitCmd $(basename "$f") )
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to
More majordomo info at

Reply via email to