Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a windows BAT script that does the following:

call git reset --hard
call git clean --force

This works, but I really want to execute it within the context of another folder, something like (this doesn't work):

call ../git reset --hard
call ../git clean --force

How can I do this? I don't want to use 'cd' for a number of reasons, not least because it seems to break the execution change (only one git command runs).

share|improve this question

Not surprising your second example doesn't work, because git is a global command (assuming you installed it that way). Doing ../git is looking for an executable named git one folder back (I would assume in Windows it is looking for git.exe or git.bat there or something similar).

Instead, git provides an option for --git-dir=<path> (as per the man page).

    Set the path to the repository. This can also be controlled by
    setting the GIT_DIR environment variable. It can be an absolute
    path or relative path to current working directory.

So assuming it works in windows as it does in Linux, you would probably want:

call git reset --hard --git-dir=../otherproject/
call git clean --force --git-dir=../otherproject/
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.