Skip to content

Instantly share code, notes, and snippets.

@kyudorimj
Last active August 5, 2025 09:06
Show Gist options
  • Save kyudorimj/9d0ab2c2d1d95e323afc6cd0e2fd0085 to your computer and use it in GitHub Desktop.
Save kyudorimj/9d0ab2c2d1d95e323afc6cd0e2fd0085 to your computer and use it in GitHub Desktop.
Bash Prompt Setup with Bold Colorized Git Branch

Bash Prompt Setup with Bold Colorized Git Branch

This guide shows you how to configure your Bash prompt on Ubuntu (and derivatives) to display:

  • Username@Host in bold green
  • Current directory in bold blue
  • Git branch in bold yellow

Prerequisites

  • Ubuntu or compatible Linux distribution
  • Git installed
  • bash-completion package (to source Git’s prompt helper)

Steps

1. Install bash-completion

sudo apt update
sudo apt install bash-completion

2. Source Git’s prompt helper

Add this to your ~/.bashrc:

# enable Git branch info
if [ -f /usr/share/git/completion/git-prompt.sh ]; then
  source /usr/share/git/completion/git-prompt.sh
fi

3. Set up your prompt (PS1)

Append this line to the same ~/.bashrc:

export PS1='\[\e[1;32m\]\u@\h\[\e[0m\]:\[\e[1;34m\]\w\[\e[0m\]\[\e[1;33m\]$(__git_ps1 " (%s)")\[\e[0m\]\$ '

What the codes mean:

  • \e[1;32m → bold green (user@host)
  • \e[1;34m → bold blue (current directory)
  • \e[1;33m → bold yellow (git branch)
  • \e[0m → reset

4. Reload your shell

source ~/.bashrc

What You’ll See

When you open a terminal, it’ll look like this:

user@device:/path/to/dir (branch-name)$

With each part colored and bold, as defined in the PS1 string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment