Quick Tip: Changing Default Directory of Git Bash

I don’t know why this gave me so much trouble, but it did. When I installed Git for Windows, the default, Bash-like Windows terminal for git, it insisted that its home directory was /s (nowhere near my Documents folder in windows).

Here is a quick tip to make Git Bash change its home directory automatically (so you don’t have to cd /blah/blah/blah every time you open it).

Open your Git for Windows client. Use vim to create a .bashrc file (this file gets automatically run every time the terminal is open):

vim .bashrc

Press ‘i’ to go into ‘Insert’ mode. Type in the following (change <my/desired/home/dir> to your new home directory).

moveHome() { cd /c/<my/desired/home/dir>; }
moveHome
export HOME=/c/<my/desired/home/dir>

Your .bashrc should look something like this:

Adding .bashrc to Git Bash

Press ‘esc’ to exit “Insert” mode. Type “:wq” and press ‘enter’ to save and exit. Now, reload your Git terminal window, and you should be in a new home directory!

EDIT (12/9/14): Added export line to .bashrc file to update environment variable.

20 thoughts on “Quick Tip: Changing Default Directory of Git Bash

Leave a Reply

Your email address will not be published. Required fields are marked *