How To Launch Git Bash from DOS Command Line?

前端 未结 9 1663
北海茫月
北海茫月 2020-12-07 08:21

I\'ve got what I\'m hoping is a simple question, but I haven\'t been able to find the answer yet. I would like to launch Git Bash from a DOS batch file. Here is what I tri

相关标签:
9条回答
  • 2020-12-07 08:41

    The answer by Endoro has aged and I'm unable to comment;

    # if you want to launch from a batch file or the command line:
    
    start "" "%ProgramFiles%\Git\bin\sh.exe" --login
    
    0 讨论(0)
  • 2020-12-07 08:47

    I used the info above to help create a more permanent solution. The following will create the alias sh that you can use to open Git Bash:

    echo @start "" "%PROGRAMFILES%\Git\bin\sh.exe" --login > %systemroot%\sh.bat
    
    0 讨论(0)
  • 2020-12-07 08:48

    I'm not sure exactly what you mean by "full Git Bash environment", but I get the nice prompt if I do

    "C:\Program Files\Git\bin\sh.exe" --login
    

    In PowerShell

    & 'C:\Program Files\Git\bin\sh.exe' --login
    

    The --login switch makes the shell execute the login shell startup files.

    0 讨论(0)
  • 2020-12-07 08:48

    I prefer to use git-bash.exe instead of sh.exe.

    start "" "%ProgramFiles%\Git\git-bash.exe" -c "tail -f /c/Windows/win.ini"
    

    You can stop closing the window when call /usr/bin/bash --login -i in the end;

    start "" "%ProgramFiles%\Git\git-bash.exe" -c "echo 1 && echo 2 && /usr/bin/bash --login -i"
    

    Note: I'm not sure this is a good way :)

    0 讨论(0)
  • 2020-12-07 08:49

    https://stackoverflow.com/a/33368029/15789

    I have posted an answer here.

    Open a Windows command window, and execute this script. If there is a change in your working directory, it will open a bash terminal in your working directory, and display the current git status. It keeps the bash window open, by calling exec bash.

    If you have multiple projects you may create copies of this script with different project folder, and call it from a main batch script.

    0 讨论(0)
  • 2020-12-07 08:54

    If you want to launch from a batch file:

    • for x86

      start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login
      
    • for x64

      start "" "%PROGRAMFILES%\Git\bin\sh.exe" --login
      
    0 讨论(0)
提交回复
热议问题