How to change the home directory in Git Bash

Greg Foster
Greg Foster
Graphite software engineer


Note

This guide explains this concept in vanilla Git. For Graphite documentation, see our CLI docs.


Git Bash is an application that provides Git command line features for Windows, simulating a Bash environment. When using Git Bash, you may find the need to change your default home directory, the default starting directory that Git Bash opens in upon launch. Changing the home directory can make work more efficient by reducing the need to navigate through multiple directories each time Git Bash is opened. This guide will provide detailed steps on how to change the home directory in Git Bash.

Join 20,000+ developers at top companies
Stop wrestling with Git commands
The Graphite CLI takes all the pain out of Git, allowing you to ship faster and stop googling Git commands.
main
diff1
diff2

In Git Bash, the home directory is where Git Bash starts upon launch. This directory is significant because it usually contains user-specific configuration files like .bashrc, .gitconfig, and others. By default, Git Bash sets the home directory to the user’s profile folder (C:\Users\<username>).

One of the most straightforward methods to change the home directory for Git Bash is by setting or modifying the Windows $HOME environment variable.

  1. Open system properties:

    • Right-click on the Start menu, select System, then click on Advanced system settings on the left sidebar.
    • Go to the Advanced tab and click on Environment Variables.
  2. Set HOME variable:

    • Under the User variables section, click on New... to create a new environment variable.
    • Set Variable name as HOME and Variable value as the path to your new desired directory, e.g., C:\GitHome.
  3. Restart Git Bash:

    • Close and reopen Git Bash to allow the change to take effect. To verify that Git Bash now opens to the correct default directory, you can use the command pwd to print the directory you're currently in. This should be the directory you set in the previous steps.

Another method to change the default starting directory for Git Bash involves modifying the properties of the Git Bash shortcut.

  1. Right-click on the Git Bash shortcut:

    • Find the Git Bash shortcut, usually on your desktop or start menu.
    • Right-click on it and select Properties.
  2. Modify the start in field:

    • In the Shortcut tab, locate the Start in field.
    • Change the path in the Start in box to your desired default directory, e.g., C:\GitHome.
  3. Save and test:

    • Click Apply, then OK to save your changes.
    • Open Git Bash using this shortcut to start directly in the new default directory.
Join 20,000+ developers at top companies
The best engineers use Graphite to simplify Git
Engineers at Vercel, Snowflake & The Browser Company are shipping faster and staying unblocked with Graphite.
main
diff1
diff2

For users who prefer a scripting approach, you can dynamically set the home directory each time Git Bash starts by editing the .bashrc file.

  1. Open .bashrc File:

    • In Git Bash, type nano ~/.bashrc to open the Bash run commands file in nano text editor.
  2. Add script to change home directory:

    • Add the following line at the end of the file:
      Terminal
      export HOME="/d/GitHome"
      cd $HOME
    • Replace /d/GitHome with your desired directory path.
  3. Save and exit:

    • Press Ctrl+O, Enter, and then Ctrl+X to save and exit nano.
  4. Source .bashrc or restart Git Bash:

    • Type source ~/.bashrc or restart Git Bash to apply the changes.

For more info on configuring Git Bash, see the official documentation.

Graphite
Git stacked on GitHub

Stacked pull requests are easier to read, easier to write, and easier to manage.
Teams that stack ship better software, faster.

Or install our CLI.
Product Screenshot 1
Product Screenshot 2