How do I open a new git bash terminal window at my current location in windows?

47,624

Solution 1

StuperUser answer is correct, but I want to add that besides adding shell script in a PATH environment it's also possible to add a simple bash alias into .bashrc or .bash_profile files.

Just create alias:

alias git-bash='/git-bash.exe & > /dev/null 2&>1'

bashrc and bash_profile it's a standard BASH configuration files, you can found them in your user home folder.

More information Bash startup files

Solution 2

Since this is specifically for a git-bash terminal, add the Git directory (C:\Program Files\Git) to your path (https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)

Then run

$ git-bash

to open a new git-bash at the current location.

But to avoid blocking the current terminal it will be necessary to use & > /dev/null 2&>1 to run in the background and pipe the result into null (see https://superuser.com/a/1314830/641), so added the command to a .sh in the directory to call it simply.

Solution 3

I know this is a couple years old, but I wanted to post this anyways.

When I use @Alex's answer, it seems like each window is attached to the other through linked processes or something. Here is my solution for completely independent new windows that start at the current location.

alias new='start "" "C:\Program Files\Git\git-bash.exe"'

That will get you one new window every time you use it. But I actually like to have 4 terminals open, so I typically use the following alias to open 3 new terminal windows at the current location:

alias new3='start "" "C:\Program Files\Git\git-bash.exe" && start "" "C:\Program Files\Git\git-bash.exe" && start "" "C:\Program Files\Git\git-bash.exe"'

Cheers!

Share:
47,624
StuperUser
Author by

StuperUser

A full stack web app developer most recently using Angular, WebAPI, Dapper. 1.5 years experience in QA and an ISTQB/ISEB Foundation Certificate in Software Testing. BA in Philosophy and Computing from University of Kent. #SOreadytohelp

Updated on September 18, 2022

Comments

  • StuperUser
    StuperUser over 1 year

    When running git bash, I can open a new bash window at my root with Alt+F2

    I can open a windows explorer window at the current directory path

    $ explorer .
    

    Trying

    $ sh
    

    to open a new terminal window at my location just returns

    sh: __git_ps1: command not found
    

    and opens the shell in the current window without git running.

    How can I quickly open a new bash shell at my location?

    • Biswapriyo
      Biswapriyo about 6 years
      Which version do you use?
    • StuperUser
      StuperUser about 6 years
      @Biswapriyo MINGW64, GNU bash, version 4.4.12(2)-release (x86_64-pc-msys)
    • Biswapriyo
      Biswapriyo about 6 years
      The feature that you've requested is available from mintty 2.8.5 which is not added in git-for-windows latest release. So wait for future release.
    • StuperUser
      StuperUser about 6 years
      @Biswapriyo looking into running $ mintty, I can add "git-bash.exe" to my path and run $ git-bash to do exactly what I want
    • Aurèle
      Aurèle almost 4 years
      @Biswapriyo My version of git-bash now ships with mintty 3.1.0. Do you happen to know how to enable the feature? Ideally with Alt-F2 or other shortcut (say I already have a task running, that I do not want to interrupt or put in the background)