Under Windows 7 I have a batch file for checking the status of some repos and outputting the returns to a file (with standard powershell issued git commands).
This works fine when launched from git shell, my question is how can I do this without launching git shell first?
So I want to be able to enter in a standard prompt or in a runnable batch file a command / commands which will launch a given batch file in git shell.
bat MS-DOS batch files (e.g. Chocolatey NuGet). You call them as you would .exe's, normally omitting the extension. Unfortunately, these . bat files are not available inside Git Bash shells, as Git Bash fails to look them up as it does .exe's.
Batch files can be run by typing "start FILENAME. bat". Alternately, type "wine cmd" to run the Windows-Console in the Linux terminal. When in the native Linux shell, the batch files can be executed by typing "wine cmd.exe /c FILENAME.
To run a batch file, move to the directory containing the file and type the name of the batch file. For example, if the batch file is named "hope. bat," you'd type "hope" to execute the batch file.
If you consider what git-cmd.bat
does, all you need to do is to set the right variable %PATH%
before your git commands in your script:
If you don't, here is what you would see:
C:\Users\VonC>git --version
'git' is not recognized as an internal or external command,
operable program or batch file.
I have uncompressed the latest portable version of msysgit.
Put anywhere a test.bat
script (so no powershell involved there) with the following content:
@setlocal
@set git_install_root="C:\Users\VonC\prg\PortableGit-1.7.11-preview20120620"
@set PATH=%git_install_root%\bin;%git_install_root%\mingw\bin;%git_install_root%\cmd;%PATH%
@if not exist "%HOME%" @set HOME=%HOMEDRIVE%%HOMEPATH%
@if not exist "%HOME%" @set HOME=%USERPROFILE%
@set PLINK_PROTOCOL=ssh
REM here is the specific git commands of your script
git --version
echo %HOME%
git config --global --list
Make sure HOME
is correctly set, because Git will look for your global git config there.
The result will give you:
C:\Users\VonC>cd prog\git
C:\Users\VonC\prog\git>s.bat
C:\Users\VonC\prog\git>git --version
git version 1.7.11.msysgit.0
C:\Users\VonC\prog\git>echo C:\Users\VonC
C:\Users\VonC
C:\Users\VonC\prog\git>git config --global --list
user.name=VonC
Note: that same script would work perfectly from a powershell session.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With