Running batch file in git shell

On Windows 7, I have a batch file to check the status of some repositories and output returns to a file (with standard powershell commands issued by git).

This works fine when starting from the git shell, my question is: how can I do this without starting the git shell?

So, I want to be able to enter a standard prompt or into the executable batch file the command / commands that launched this batch file in the git shell.

+6
source share
2 answers

If you think git-cmd.bat , all you have to do is set the correct %PATH% variable before your git commands in the script:

If you do not, here is what you will see:

 C:\Users\VonC>git --version 'git' is not recognized as an internal or external command, operable program or batch file. 

I have an uncompressed latest portable version of msysgit .

Put somewhere a test.bat script (so that no force is involved there) with the following contents:

 @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 installed correctly, 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: the same script works fine with powershell session.

+4
source

It looks like your git executable is just not available for use on the command line.

Just add c:\Users\[your_login]\AppData\Local\GitHub\PortableGit_[hash]\bin (or c:\Users\[your_login]\AppData\Local\GitHub\PortableGit_[hash]\cmd ) in your variable Path Replacing [your_login] and [hash] actual data.

But I believe that the location of files will vary from version to version, so if you are a heavy git user, consider installing msysGit . It will automatically add its executable file to the system path (the corresponding option is available during installation).

Moreover, there is a project called mysysGit-UTF8 that claims to have full UTF-8 support on Windows. I did not notice the difference.

+2
source

Source: https://habr.com/ru/post/919148/


All Articles