How do I launch a Git Bash window with particular working directory using a script?

windows git bash start in directory
keyboard shortcut to open git bash
git bash commands
git bash setup
git bash current directory
how to open a file in git bash
bash.exe command line arguments
git-bash open new terminal

How can I launch a new Git Bash window with a specified working directory using a script (either Bash or Windows batch)?

My goal is to launch multiple Git Bash windows from a single script, each set to a different working directory. This way I can quickly get to work after booting the computer instead of having to open Git Bash windows and navigating each one to the correct working directory.

I am not asking how to change the default working directory, like this question does, but to launch one or more terminal windows with different working directories from a script.

Another option is to create a shortcut with the following properties:

Target should be:

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

Start in is the folder you wish your Git Bash prompt to launch into.

Git: Open Git-Bash in specific directory, cd C:\specific\dir\to\open && start "" "C:\Program Files\Git\bin\sh.exe" Git-bash then opens in the current directory (which was changed to &gwd. ). Finally, whenever git-bash closes, the exit command is given, closing the Windows For convenience, you can add your script to the taskbar with the steps  Directly through Git Bash using commands; By opening Git Bash in the desired folder . Browse to desired Directory through Commands in Git Bash. You can change the directory inside Git Bash with the help of cd command. cd command is commonly used in the shell of your system (cmd) for the same purpose. Here, I will change the directory to ToolsQA

Git Bash uses cmd.exe for its terminal plus extentions from MSYS/MinGW which are provided by sh.exe, a sort of cmd.exe wrapper. In Windows you launch a new terminal using the start command.

Thus a shell script which launches a new Git Bash terminal with a specific working directory is:

(cd C:/path/to/dir1 && start sh --login) &
(cd D:/path/to/dir2 && start sh --login) &

An equivalent Windows batch script is:

cd \path\to\dir1
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login 
cd \path\to\dir2
start "" "%SYSTEMDRIVE%\Program Files (x86)\Git\bin\sh.exe" --login 

To get the same font and window size as the Git Bash launched from the start menu, it is easiest to copy the start menu shortcut settings to the command console defaults (to change defaults, open cmd.exe, left-click the upper left icon, and select Defaults).

Most Common Directory commands on Git Bash/Shell, How to create a folder on the sytem before Initializing git repository. Since, now we are very close to start doing Git activities, but we must know few Common You can change the directory inside Git Bash with the help of cd and then delete these folder and create a single directory called First Project. How to launch a Git Bash window with particular working directory using a script? (5) Windows 10. This is basically @lengxuehx's answer, but updated for Win 10, and it assumes your bash installation is from Git Bash for Windows from git's official downloads.

Try the --cd= option. Assuming your GIT Bash resides in C:\Program Files\Git it would be:

"C:\Program Files\Git\git-bash.exe" --cd="e:\SomeFolder"

If used inside registry key, folder parameter can be provided with %1:

"C:\Program Files\Git\git-bash.exe" --cd="%1"

How to Start Git Bash In Your Project Directory, Git Bash is a package that installs Bash, some common bash utilities, and Git on a Once downloaded find the included .exe file and open to execute Git Bash. working directory. ls is equivalent to DIR on a Windows console host terminal. Open Git Bash in your Windows Start menu. Once open you will see the following, an empty window with a dollar sign and a flashing cursor: From here you can type “dir” or “ls”. “ls” is a command to list files in Unix and Unix-like operating systems.

Let yet add up to the answer from @Drew Noakes:

"C:\Program Files\Git\git-bash.exe" --cd=C:\GitRepo

The cd param should be one of the options how to specify the working directory.

Also notice, that I have not any --login param there: Instead, I use another extra app, dedicated just for SSH keys: Pageant (PuTTY authentication agent).

Start in:

The same possible way, as @Drew Noakes mentioned/shown here sooner, I use it too.

Shortcut key:
Ctrl + Alt + B

Such shortcuts are another less known feature in Windows. But there is a restriction: To let the shortcut take effect, it must be placed somewhere on the User's subdirectory: The Desktop is fine.

If you do not want it visible, yet still activatable, place this .lnk file i.e. to the quick launch folder, as that dir is purposed for such shortcuts. (no matter whether displayed on the desktop) #76080 #3619355

"\Application Data\Microsoft\Internet Explorer\Quick Launch\"

Git bash: Definition, commands, & getting started, Hello, Is is possible to launch git-bash from the directory that contains the Is it possible to launch a shell in the current repo from Sublime Merge? If not, does Sublime Merge have the same sort of scripting capabilities as ST3? (in your case a git bash window that opens in a particular folder) and then  Create a new file in the Git directory by typing the following command from either the Bash or Windows command line. The following command opens and creates a file called example.txt in Notepad . In Git Bash, you could also use the touch command to create a blank new file and then type "start <name of file>" to open the file in your favorite

In addition, Win10 gives you an option to open git bash from your working directory by right-clicking on your folder and selecting GitBash here.

Possible to launch git-bash from current repository?, It's not a complicated task to install Bash on Ubuntu on Windows 10, and it to open Bash on a particular working directory using the Registry. The Bash command pwdis used to print the 'present working directory'. pwdis equivalent to executing cd on a DOS(Windows console host) terminal. This is the folder or path that the current Bash session resides in. The Bash command lsis used to 'list' contents of the current working directory.

How to launch Bash shell from right-click context menu on Windows , The shell is a program on your computer whose job is to run other programs. The most common shell is bash and it gets thrown around as a proxy for “shell” sometimes, In Happy Git, sometimes we demo the use of a shell for certain tasks, like every effort to put you in a sane working directory, i.e. in the current project. I'm trying to add a new terminal (Git Bash) to the new Windows Terminal, however I can't get it to work. I tried changing the commandline property in the profiles array to git-bash.exe but no luck.

A The shell, A shell is a specific kind of CLI. Open the Start menu by clicking on the Windows icon and typing “Git Bash” into the search That means you can now work with your files and folders using Bash commands instead of Windows commands. Let's say you have a script To run it (using Git Bash), you do the following: [a] Add a "sh-bang" line on the first line (e.g. #!/bin/bash) and then [b]: # Use ./ (or any valid dir spec): ./ Note: chmod +x does nothing to a script's executability on Git Bash. It won't hurt to run it, but it won't accomplish anything either.

Command Line Interface Setup, To ensure Git is properly installed and to create a working directory for GitHub, you will Windows: Git Bash came with your download of Git for Windows. I.e., the directory that the computer assumes we want to run commands in unless we All of the above commands are bash commands, not Git specific commands. I store all of my local repositories in a particular directory. I wrote these scripts to automate one or more git commands to run on each repository within that directory. It could also be used to do a general clean up before committing anything to your repository. Here are two ways to do it. Method 1:

  • @StevenVascellaro Edited question to explain why this isn't a dupe.
  • That makes sense. I have retracted my duplicate vote.
  • Kudos! Never knew Start in had something to do with the working directory a program thinks it's in.
  • This is the easiest method. Afterwards, I pinned that short cut to task bar then Windows + 1, I keep that as first item of the task bar, opens the repo with git-bash directly.
  • This works for me: cd to the directory I want Git Bash to start, and then running the start command in your example will really give me a Git Bash terminal in that dir. Are you sure you are not doing a cd $HOME (or cd without args) somewhere in your bash rc files? (Like .bashrc, .profile, ...) Also keep in mind the drive letter. If you want to start Git Bash on the X: drive, then doing cd x:\path won't cut it, you have to do x: and then cd \path before start
  • You are right! I was missing the fact that you cannot simply cd x:\path. Will edit my solution accordingly.
  • A perfect solution! Let me only add, that default cmd.exe settings are not the same, as default Git Bash settings upon Git Bash installation! And you have to understand differences between default settings (Defaults from context menu) and current one (Properties). So, what I did was: (1) open Git Bash, select Properties (current settings), (2) tweak it, to exactly, what I want (font, window size + position), (3) open cmd.exe, select Defaults, (4) copy-paste settings from Git Bash to cmd.exe. Then OK in cmd.exe'settings, Cancel in Git Bash's settings and voila!
  • How would I use the %1 registry parameter?
  • current answer is soo obsolete, this one should be the one!
  • For me --cd="%V" worked. Windows 7.
  • For the record, the default git bash entry inside the registry at HKEY_CLASSES_ROOT\Directory\Background\shell\git_shell\command is "C:\Program Files\Git\git-bash.exe" "--cd=%v."