Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 772
mariachimike Avatar asked Mar 05 '11 12:03

mariachimike


People also ask

How do I run a shell script from a batch file?

You can allocate STDIN, STDOUT, and STDERR as z/OS UNIX files, using the PATH operand on the DD statements. You can also allocate STDOUT and STDERR as MVS data sets. Example: User TURBO runs a shell script in batch, as follows: The STDIN ddname defines a shell script to be invoked, /u/turbo/bin/myscript.sh.

How do I run git bash from command line?

Launch Git Bash console by clicking on the Start button, type git, and click on Git Bash. 2. Run the below git config command to add your name ( YourName ) as your git username ( user.name ). The git config command administers configuration variables that control how Git looks and operates.


2 Answers

You can also run a shell script to run multiple commands

#! /bin/bash cd /c/GitRepo/PythonScripts git status read -p "Press enter to continue" 

then call that from your cmd line:

"c:\Program Files (x86)\Git\bin\sh.exe" --login -i -c "/c/GitRepo/PythonScripts/statusandwait.sh" 
like image 36
rugg Avatar answered Sep 23 '22 21:09

rugg


"C:\Program Files (x86)\Git\bin\sh.exe" --login -i -c "git archive master | tar -x -C $0" "%~1" 
like image 78
Erik Avatar answered Sep 23 '22 21:09

Erik