0

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).

1

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).

--git-dir=<path>
    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/
0

Update:

--git-dir= Set the path to the repository (".git" directory).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 for the OP example :

call git reset --hard --git-dir=../otherproject/.git
call git clean --force --git-dir=../otherproject/.git

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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