← All posts

Customize Your Git Bash Prompt to Show Only the Current Folder

Learn how to simplify your Git Bash prompt by displaying only the current folder instead of the full directory path.

🎯 Goal

By the end of this guide, your Git Bash prompt will display only the current folder name instead of the entire directory path, making your terminal cleaner and easier to read.

Before

Saidul islam rajib@Rajib MINGW64 ~/Desktop/Learning/AWS_Demo_Project/automation (feature/update)
$

After

automation $

Or, if you choose to keep the current Git branch:

automation (feature/update) $

Why Customize the Prompt?

Every time Git Bash is ready to accept a command, it displays a prompt.

By default, the prompt contains:

  • Username
  • Computer name
  • Current working directory (full path)
  • Current Git branch (when inside a Git repository)

As your projects become more deeply nested, the prompt grows longer and takes up unnecessary space.

A shorter prompt helps you:

  • Focus on your commands.
  • Read terminal output more easily.
  • Reduce visual clutter.
  • Improve your overall development experience.

What is PS1?

PS1 stands for Prompt String 1.

It is a special Bash environment variable that controls how your command prompt is displayed.

Whenever Bash waits for your next command, it reads the value stored in PS1 and renders the prompt accordingly.

For example:

PS1='\W \$ '

This changes the appearance of your prompt.


Understanding the Prompt Syntax

PS1='\W \$ '

Let's break it down.

Syntax Meaning
PS1 Bash variable that defines the prompt.
= Assigns a new value to the variable.
'...' Everything inside the quotes becomes the prompt format.
\W Displays only the current folder name.
\$ Displays $ for a normal user or # for the root user.

For example, if your current directory is:

~/Desktop/Learning/AWS_Demo_Project/automation

then:

\W

produces:

automation

Where Should This Configuration Be Saved?

Bash automatically loads several configuration files when it starts.

One of the most commonly used files is:

~/.bashrc

Here:

  • ~ represents your home directory.
  • .bashrc stores Bash startup configurations.

Any settings placed in this file are automatically applied whenever you open Git Bash.


Step 1: Open the Bash Configuration File

Open Git Bash and run:

code ~/.bashrc

Note: If the file does not already exist, VS Code will create it automatically.

Alternatively, you can use Nano:

touch ~/.bashrc
nano ~/.bashrc

Step 2: Configure the Prompt

Add the following line to the bottom of the file:

PS1='\W \$ '

Save the file.


Step 3: Reload the Configuration

Instead of closing and reopening Git Bash, reload the configuration immediately:

source ~/.bashrc

The source command tells Bash:

Read this file again and apply the latest configuration immediately.

Without running source, the changes won't appear until you open a new terminal window.


Result

Your prompt changes from:

Saidul islam rajib@Rajib MINGW64 ~/Desktop/Learning/AWS_Demo_Project/automation (feature/update)
$

to:

automation $

Keeping the Current Git Branch

If you frequently work with Git, it's often useful to keep the current branch visible.

Instead of:

PS1='\W \$ '

use:

PS1='\W$(__git_ps1 " (%s)") \$ '

Now your prompt becomes:

automation (feature/update) $

This provides a cleaner prompt while still showing which branch you're currently working on.


Common Prompt Escape Sequences

Bash provides many escape sequences that can be used inside PS1.

Escape Sequence Description Example Output
\u Username rajib
\h Hostname MINGW64
\H Full hostname Rajib-PC.local
\w Full current directory ~/Desktop/Project
\W Current folder only automation
\d Current date Thu Jul 23
\t Current time (24-hour) 21:45:12
\T Current time (12-hour) 09:45:12
\A Current time (HH:MM) 21:45
\n New line (moves prompt to next line)
\$ $ or # depending on user privileges $

Example:

PS1='\u@\h:\W \$ '

Output:

rajib@MINGW64:automation $

Useful Commands

Open the configuration:

code ~/.bashrc

Reload the configuration:

source ~/.bashrc

View the current prompt configuration:

echo $PS1

Display the current directory:

pwd

Summary

In this guide, you learned:

  • What the Bash prompt is.
  • What the PS1 variable controls.
  • Why .bashrc is used for Bash customization.
  • How to display only the current folder.
  • How to reload Bash configuration using source.
  • How to keep the current Git branch visible.
  • Several useful prompt escape sequences for further customization.

Customizing your terminal prompt is a small change, but it greatly improves readability and productivity—especially when working with deeply nested project directories.