Understanding the Git Bash environment
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.
Basic commands to change directories
To change directories in Git Bash, you use the cd
(change directory) command.
Syntax:
cd [options] <directory>
Where <directory>
is the path to the directory you want to change to.
Examples:
Changing to a specific directory:
Terminalcd /c/Users/Username/DocumentsThis command changes the current directory to the Documents folder of the user
Username
.Going up one directory:
Terminalcd ..This moves the current working directory up one level.
Changing to the home directory:
TerminalcdJust typing
cd
without any arguments will take you to your home directory, which is usually your user folder.
Tips for navigating in Git Bash
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).
- Absolute paths start from the root directory (e.g.,
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.Using shortcuts:
~
(tilde) refers to the home directory..
(dot) refers to the current directory...
(dot-dot) refers to the parent directory.
Navigating to mounted drives: In Git Bash, drives are mounted under the root directory
/
. To access other drives:Terminalcd /d/This command would change to the D: drive.
Handling spaces in directory names: If a directory name contains spaces, enclose the name in quotes or use a backslash before the space:
Terminalcd "Program Files"cd Program\ Files
Common problems and solutions
- 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.