13

I'm trying to automate my work environment set up using a batch file. I'm stuck at a point where I am not able to start the MingW64 Console from command line.

start "" "%ProgramFiles%\Git\bin\sh.exe" --login works fine but it seems to open a different shell window than that I am looking for. I'll explain this with pictures.

What it opens is a default cmd style window with bash integrated. This window isn't even resizeable
enter image description here

What I want is
enter image description here

I was trying to use the command start "" "%ProgramFiles%\Git\git-bash.exe" --login -i -c /bin/bash but it seems to quickly close the shell after opening it. If I execute the same file from explorer, the shell doesn't close automatically.

Here is my full batch file for reference

@echo on

REM start PHP and MYSQL
start "" mysql_server\UniServerZ\UniController.exe start_both

REM Open PhpMyAdmin
start "" http://localhost/us_opt1/

REM Open Folders
start "" %SystemRoot%\explorer.exe "E:\work\"

REM Open Git Bash Instance
:: in order to open the shell in that path
cd E:\work\
:: start "" "%ProgramFiles%\Git\bin\sh.exe" --login
start "" "%ProgramFiles%\Git\git-bash.exe" --login -i -c /bin/bash

REM start sublime text
start "" "E:\Sublime Text Build 3083 x64\sublime_text.exe"
Atif
  • 10,623
  • 20
  • 63
  • 96

3 Answers3

16

git-bash.exe -i -c "/bin/bash" seems to work better.
This issue illustrates various other ways to call git-bash.exe, but concludes:

Preferred way to run git-for-windows is using git-cmd.exe:

c:\git\git-cmd.exe --command=usr/bin/bash.exe -l -i

That however only opens a session in the current cmd, while git-bash.exe opens a new windows.

Combined with this question (to open a new console) and this one (to avoid two CMD windows), I would use:

start /b cmd /c git-bash.exe -i -l -c "/bin/bash"

The OP Atif Mohammed Ameenuddin reports in the comments this as working fine:

start "" "%ProgramFiles%\Git\git-bash.exe"
Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Thanks for the insight on this. `start /b cmd /c "%ProgramFiles%\Git\git-bash.exe" -i -l -c "/bin/bash"` doesn't seem to work, but `start "" "%ProgramFiles%\Git\git-bash.exe"` works – Atif Dec 14 '15 at 17:54
  • @AtifMohammedAmeenuddin Great! I have included your conclusion in the answer for more visibility. – VonC Dec 14 '15 at 18:33
  • While this is working for me, I'm finding I have to press Ctrl+C once the Git bash window opens in order to actually get to the prompt. Has anyone else experienced this? – Tim Malone Nov 14 '17 at 00:12
  • @TimMalone Strange. What git version are you using? On which Windows? – VonC Nov 14 '17 at 05:23
  • @VonC 2.8.1 on Windows 10. Maybe I should try updating Git, I'm a little behind. – Tim Malone Nov 14 '17 at 05:24
  • @TimMalone Agreed. Try the latest 2.15. – VonC Nov 14 '17 at 05:25
0

work on windows 10

start "" "%ProgramFiles%\Git\bin\sh.exe" --login

;

start "" "%ProgramFiles%\Git\git-bash.exe"

tx !

  • 2
    You answer includes very little detail and nothing to indicate what new information your answer provides compared to the existing answers. – Keith Langmead May 21 '23 at 21:02
0

Oneline to open it in a different path, and for example execute a command:

start "" "%ProgramFiles%\Git\git-bash.exe" --cd="E:\work" -c "git status; /bin/bash"

If there is a command it's always at the end.

ltapia
  • 3
  • 1
  • 2