[git] How do I change the default location for Git Bash on Windows?

I am using Git on Windows 7 and access my repositories through Git Bash. How can I change the default location that Git Bash opens in a convenient folder when I start it?

It's somewhat time consuming to navigate to htdocs, and then a specific folder. Is there a way to change the configuration file to have it open elsewhere? Or would it be possible to write a .sh file to do this?

Unfortunately Git Bash won't open my htdocs folder shortcut on my desktop, and it takes using cd 5 times to get to my desired directory.

This question is related to git windows-7 git-bash

The answer is


Windows 10 tested solution

  • Type git bash in search

  • Right click on it and choose open file location

  • Right click on it and choose properties

  • At target remove --cd-to-home from "C:\Program Files\Git\git-bash.exe" --cd-to-home

  • At start in put the path of the directory you want it to start at for example Start in: C:\xampp\htdocs


Right click on Git Bash shortcutand then go to properties.
In properties inside start in option add the location of the directory you want to start Git Bash in and apply the changes.


If you're like me, and the way you get to Git is windows key + G + I + Enter, then you can simply hit the windows key, search for Git, right click on the resulting Git Bash icon, select properties, and change the Start in: field.

I'm not exactly sure what this does, because I'm not exactly sure what Git on Windows is (a facade on top of sh which itself is a facade on cmd?), but in any case, you can now pin the shortcut that Windows pulls up on a search for "Git" to your taskbar, or to your desktop, and it will still start in whatever directory you set it to.


I am using Git bash on Windows 10, here is my solution:

  1. Close all git bash sessions
  2. Hit windows key and type: env; then click Edit environment variables for your account (control panel)
  3. Under "User variables for ...."; hit New button
  4. Variable Name: HOME
  5. Variable value: path where you would like ~/ to be in git bash

Open a git bash session and test it by typing: pwd and double check by doing cd ~/ && pwd


Once you have updated the Start in: field make sure to remove the --cd-to-home at the end of the Target: field


I read it somewhere and it worked for me.

First check in git bash what is the HOME location. Open git bash and run

echo $HOME

Now change the HOME path by opening cmd and run

setx HOME "path/to/.ssh/loc" (I gave C:\Users\aXXXX)

Now cross check by running the echo command in git bash.


Git bash is used to play with bash commands. So I use bash method itself in windows Git bash

Edit your .bash_profile (create it if you doesnot have one - see below how to create). Enter the following lines.

Add these lines to the file

alias ws="cd /d/workspace/"
ws

My .bash_profile looks like this

Smilyface@SmilingMachine /d/workspace
$ cat ~/.bash_profile
alias ws="cd /d/workspace/"
ws

How to create a new .bash_profile ?

touch ~/.bash_profile

OR write into the file directly

vi ~/.bash_profile 

Simple, aha !


I liked Peter Mortenson's answer, but I would like to expand.

'cd ~' in the .bashrc file causes the "Git Bash Here" feature of Git Bash to stop working. Instead, add this if statement to the .bashrc file:

if [ "$PWD" == '/' ]
then
        cd ~
fi

This will change to the home directory when Git Bash is run on its own, but when "Git Bash Here" is run, the current working directory will not be changed.


the only way that worked for me on windows 10:

  1. right-click gitbash shortcut -> proporties
  2. change target as: "C:\Program Files\Git\git-bash.exe" --cd=C:\Users\test\Desktop\

This will always open desktop path


I tried the following; it helped me. I hope it help you also.

cd /c/xampp/your-project

Add this line to your .bashrc file:

cd C:/xampp/htdocs/<name of your project>;

If the .bashrc file doesn't exist, create one in your root folder. For me it is: C:\Users\tapas\

Save .bashrc and open Git Bash. That's it!


Make a Git Bash shortcut to Desktop for convenience then right click on the icon goto properties. Here you will find the Start in: section with a text box. Replace the path you want, for example like:

%USERPROFILE%\Desktop

Then open it directly by clicking on the icon. You will get the default Desktop path in Git Bash.


The working solution listed are great, but the problem occurs when you want multiple default home for your git-bash.

A simple workaround is to start git-bash using bat script.

git-bash-to-htdocs.bat

cd C:\xampp\htdocs
"C:\Program Files\Git\git-bash.exe" 

The above of course assume git-bash is installed at C:\Program Files\Git\git-bash.exe

You can create multiple .bat file so your git-bash can start where it want to be


Just type the path of your local directory (Git project home directory) in the properties of Git Bash. I.e. set path C:\yourprojsctdirectory to Git Bash's properties field "Execute In" or (Ausführen in). That's it!

Now double click Git Bash. The Git header will be on your "yourprojsctdirectory".


Open the properties of the bash and change to "Start in" to where you want to start in. After this, (I had this problem and I solved it by doing this) go to target and delete the --cd-to-home parameter part after "C:\Program Files\Git\git-bash.exe" . Only THEN will you start in the "Start in" directory that you specified.


The easiest way without installing msysgit is right click on the Git Bash shortcut icon ? Start in: ? "C:\Program Files (x86)".

Change the Start in entry and point out the Git Bash starting position. If you don't remove the --cd-to-home part from the Target box, the Start in change gets overridden.


Open this file:

C:\Program Files\Git\etc\bash.bashrc

And append the following line:

cd /c/Users/<User>/Documents/path/to/your/repos

Restart Git bash


Add "cd your_repos_path" to your Git profile, which is under the %.


Examples related to git

Does the target directory for a git clone have to match the repo name? Git fatal: protocol 'https' is not supported Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools) git clone: Authentication failed for <URL> destination path already exists and is not an empty directory SSL_connect: SSL_ERROR_SYSCALL in connection to github.com:443 GitLab remote: HTTP Basic: Access denied and fatal Authentication How can I switch to another branch in git? VS 2017 Git Local Commit DB.lock error on every commit How to remove an unpushed outgoing commit in Visual Studio?

Examples related to windows-7

ng is not recognized as an internal or external command Why am I getting ImportError: No module named pip ' right after installing pip? How to Delete node_modules - Deep Nested Folder in Windows Telnet is not recognized as internal or external command Multiple -and -or in PowerShell Where-Object statement How do I set ANDROID_SDK_HOME environment variable? Run Batch File On Start-up Why isn't .ico file defined when setting window's icon? How to access shared folder without giving username and password Can't start hostednetwork

Examples related to git-bash

"Permission Denied" trying to run Python on Windows 10 Adding Git-Bash to the new Windows Terminal How do I use Bash on Windows from the Visual Studio Code integrated terminal? How can I change the user on Git Bash? Change drive in git bash for windows Running .sh scripts in Git Bash Set an environment variable in git bash Python not working in the command line of git bash Change the location of the ~ directory in a Windows install of Git Bash Username and password in command for git push