Data report"State of code review 2024" is now liveRead the full report

How to change directories in Git Bash for Windows

Kenny DuMez
Kenny DuMez
Graphite software engineer


Note

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


Git Bash for Windows provides a Unix-like command line interface, which is different from the typical Windows Command Prompt. Paths are generally expressed in Unix format, and many Unix commands are available.

To change directories in Git Bash, you use the cd (change directory) command.

Terminal
cd [options] <directory>

Where <directory> is the path to the directory you want to change to.

  • Changing to a specific directory:

    Terminal
    cd /c/Users/Username/Documents

    This command changes the current directory to the Documents folder of the user Username.

  • Going up one directory:

    Terminal
    cd ..

    This moves the current working directory up one level.

  • Changing to the home directory:

    Terminal
    cd

    Just typing cd without any arguments will take you to your home directory, which is usually your user folder.

  1. Using absolute and relative paths:

    • Absolute paths start from the root directory (e.g., /c/Windows/System32).
    • Relative paths start from the current directory (e.g., ./folder indicates a folder named "folder" in the current directory).
  2. Tab completion: Pressing the Tab key after typing a part of the directory name will auto-complete it based on existing directory names. This is helpful in avoiding typing errors and speeding up command entry.

  3. Using shortcuts:

    • ~ (tilde) refers to the home directory.
    • . (dot) refers to the current directory.
    • .. (dot-dot) refers to the parent directory.
  4. Navigating to mounted drives: In Git Bash, drives are mounted under the root directory /. To access other drives:

    Terminal
    cd /d/

    This command would change to the D: drive.

  5. Handling spaces in directory names: If a directory name contains spaces, enclose the name in quotes or use a backslash before the space:

    Terminal
    cd "Program Files"
    cd Program\ Files
  • Directory not found: This usually happens due to typos or incorrect path usage. Double-check the path and the existence of the directory.
  • Permission issues: Sometimes, you might not have the necessary permissions to access certain directories. Running Git Bash as an administrator might resolve these issues.

For more information see the official Git Bash for Windows docs.

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