Do you want to know how to change directory (folder) in Git Bash? In this post I’ll explain how to do just that, along with the answer to the more specific question of how to change the default home directory in git bash. Additionally I’ll cover which git bash command to use to list all folders or directories, including hidden folders.
Find the current folder in Git bash
First of all open git bash. At this point you might want to find out what directory you’re in – so let’s start by doing that, by typing :
… and you’ll see the path of the current directory, something like this:
In case you’re wondering
pwd stands for Print Working Directory.
So to change the current directory or folder, type
cd followed by the path to the folder / directory you want to change to. In the following example I use
pwd to tell me what my current folder is, and then
cd src to change to the src folder which I knew existed in that location:
How to list the folders / directories in git bash
But what if we didn’t know what the subfolder was called? We would need to know how to list all the folders in Git bash, in which case we would type
ls to show a list of the contents of the current directory. In the image shown here you can see all the folders shown in blue – node_modules, public, and src. If you wanted to see hidden folders as well you need to type ls -a.
‘Git bash default directory’ – how to change the home directory in Git bash
If it’s the home directory – or default folder (they mean the same thing) you want to change in Git Bash then you have to change the %HOME% Environment Variable on your PC.
- Click the start menu, start typing “Environment” and then select “Edit environment variables for user account”.
- Under user variables click New and then set the name of the variable to be HOME and the value to be whatever folder path you want to be your new default.
- Save it, and close Git Bash if it’s open.
Now when you open Git Bash and type
pwd you should see the new folder is automatically where you are.
To change your current directory to the users home directory type
cd ~. The ~ represents the home directory which is set in the %HOME% environment variable.
Summary of git bash commands
So the git bash command to change folder is
The command to see what directory we are currently in is
The command to list all folders or directories in git bash is
ls -a (-a will make sure hidden folders are included).