I have written DOS commands and GIT commands in notepad and convering to .BAT file.After executing the Batch file only DOS command will be executed GIT commands not executing.How do i run GIT commands using Batch(.BAT) file
3 Answers
Make sure that git is in your PATH system environment variable and if it is then you should be able to call git just like you normally would in the terminal. Please note that you will need to restart the terminal (cmd) for path changes to take effect.

- 13,379
- 7
- 57
- 73
-
@Robert,i tried but it is not working.itwas logged and connected to GIT by running a batch file but commands were not executed..Please let me know your thoughts – Aravinth Feb 22 '11 at 11:34
-
@Aravinth Okay, can you do a few things for me, Type 'echo %PATH%' on the terminal and give me the output in a pastie. Then maybe show me a snippet of your batch file (or just dump your whole batch file in a pastie) and edit your question to post it so that I can see that information. With that data I should be able to spot what is going wrong or know what the next step is. – Robert Massaioli Feb 22 '11 at 11:40
-
@Robert,`C:\Program Files\Windows Resource Kits\Tools\;C:\WINNT\system32;C:\WINNT;C:\WINN T\System32\Wbem;C:\WINNT\system32\nls;C:\WINNT\system32\nls\ENGLISH;c:\Program F iles\Novell\ZENworks\;C:\Program Files\Novell\SecureLogin\;c:\Program Files\Pers onal Communications\;c:\Program Files\IBM\Trace Facility\;C:\WINNT\system32\Wind owsPowerShell\v1.0; – Aravinth Feb 22 '11 at 11:47
-
@Aravinth: Um, where am I supposed to find it exactly? – Robert Massaioli Feb 22 '11 at 11:50
-
@Robert,c:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\ Common7\IDE\;c:\Program Files\Microsoft SQL Server\100\Tools\Binn\;c:\Program Fi les\Microsoft SQL Server\100\DTS\Binn\;c:\Program Files\Microsoft SQL Server\90\ Tools\binn\;C:\git\tools\nant;Z:.;Y:.;X:. – Aravinth Feb 22 '11 at 11:53
-
@Robert,And My Batch files contains `cd C: cd Program Files cd Git cd bin sh.exe --login -i cd c: cd git cd framework` In the above code it works fine till --login-i (i.e connecting to GIT) after consecutive commands it is not executing – Aravinth Feb 22 '11 at 11:53
-
@Robert, i forgot one command...after cd framework it shows `git pull` – Aravinth Feb 22 '11 at 11:57
-
@Aravinth: Ah there we go, the second that you use ssh you are logging into another machine and therefore the shell script running on your current machine will not start running until you come back to this machine. What you really want to do is run a script on the remote machine. This page explains how to: http://bashcurescancer.com/run_remote_commands_with_ssh.html – Robert Massaioli Feb 22 '11 at 11:58
-
@Aravinth damn, I read too fast and read sh.exe as ssh.exe. Sorry. Also, compress all of those cd's into one line like cd "C:\Program Files\Git\bin" so that you only have one cd command per path. Also I do not see you calling git anywhere in that script but that could be due to stack overflow comments. Could you pleas put your script in a pastie: http://pastie.org/ – Robert Massaioli Feb 22 '11 at 21:37
The git command in Msysgit is implemented by using a batch file to wrap all the calls and run the correct executable with the correct environment variables. You can not execute a batch file from another batch file normally like you would an executable, you have to use a special command to run them. If my memory is correct that command is call
and would be used as call git push
for example.

- 9,143
- 2
- 28
- 25
Hai All, Finally I got the solution for my question.By using below code snippet, we can run the Git using BAT file
"c:\Program Files\Git\cmd\git.cmd" pull > c:\platform.txt
the above code using from BAT file instead of using git pull
or git push
and any git command using GIT Bash
Thanks to all for posting your valuable comments and partial answer

- 69
- 2
- 5