Home » Git bash » How to change directory in Git Bash

How to change directory in Git Bash

Do you want to know how to change directory in Git Bash? In this post I’ll explain how to do just that using cd in Git Bash, along with the answer to the more specific question of how to change the default home directory in git bash. You’ll also learn which git bash command to use to list all folders or directories, including hidden folders. So for anything to do with how to change the directory in Git Bash, read on.

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 :

pwd

… and you’ll see the path of the current Git Bash directory, something like this:

git bash what directory am i in

In case you’re wondering pwd stands for Print Working Directory.

How to change directory in Git Bash using cd

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:

change which folder or directory you are in git bash

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.

how to list folders and directories in git bash

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.

  1. Click the start menu, start typing “Environment” and then select “Edit environment variables for user account”.
  2. 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.
  3. 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

  • The git bash command to change folder is cd
  • The command to see what directory we are currently in is pwd
  • List all folders or directories in git bash is ls -a (-a will make sure hidden folders are included)

You may also be interested in: