How do I write a batch file which opens the GitBash shell and runs a command in the shell?

mariachimike picture mariachimike · Mar 5, 2011 · Viewed 69.7k times · Source

I'm on Windows 7 trying to use a batch file to open the GitBash shell and make a git call. This is the contents of my batch file:

REM Open GitBash 
C:\Windows\SysWOW64\cmd.exe /c ""C:\Program Files (x86)\Git\bin\sh.exe" --login -i"
REM retrieve archive
git archive master | tar -x -C %~1
REM quit GitBash
exit

I noticed that the GitBash is logging out before the next command "git archive...". Does anybody know if I can pass the command into GitBash and how?

Mike

Answer

Erik picture Erik · Mar 5, 2011
"C:\Program Files (x86)\Git\bin\sh.exe" --login -i -c "git archive master | tar -x -C $0" "%~1"