How To Launch Git Bash from DOS Command Line?

2019-01-16 02:16发布

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 tried so far:

  1. Launched Git Bash from Win 7 Start button
  2. Used CTRL+ALT+DEL to identify the process as "sh.exe"
  3. Launched sh.exe from batch file using start command

    start sh.exe
    

However, this does not launch the full Git Bash environment. Git Bash usually has "MINGW32" in the title bar, but sh.exe has a full path to ... Git\bin\sh.exe. It feels to me like there are some overlays or dependencies that I'm not aware of possibly, that also need to be loaded (pulled in? imported?).

This was one of the top results I found through searching the web, but it doesn't make complete sense to me and I'm not sure if it applies exactly to my situation:

Running git from Windows Cmd line: Where are key files?

I'm a beginner in the world of DOS batch scripting.

8条回答
走好不送
2楼-- · 2019-01-16 03:01

I prefer, putting git in environment variable and just calling

c:\Users\myname>sh
or 
c:\Users\myname>bash

Steps to create Environment variable (Win7)

  • From the desktop, right click the Computer icon.
  • Choose Properties from the context menu.
  • Click the Advanced system settings link.
  • Click Environment Variables.
  • In the section System Variables (or User variables), hit button new, put variable name as GIT_HOME, value as ; for me it is c:\tools\git
  • find the PATH environment variable and select it. Click Edit. If the PATH environment variable does not exist, click New.
  • In the Edit System Variable (or New System Variable) window, add to exiting value ;%GIT_HOME%/bin;%GIT_HOME%;. Click OK. Close all remaining windows by clicking OK.
  • open new Command prompt window, and just type sh.exe or sh or bash.exe or git-bash
查看更多
干净又极端
3楼-- · 2019-01-16 03:07

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.

查看更多
登录 后发表回答