Bash Git Prompt for Ubuntu 24.04
A customizable Bash prompt with five clean themes, showing live Git repository status — branches, staged files, changes, stashes, and more.
Although designed for Ubuntu 24.04, it also runs smoothly on Fedora and most modern Linux distributions.
Features
- Displays the current Git branch and live repository status
- Works across five switchable themes (changeable in real time)
- Shows staged, changed, untracked, stashed, and remote indicators
- Detects clean vs. dirty repository state instantly
- Compatible with Ubuntu, Fedora, and most POSIX-compatible shells
- Includes a Nerd Font installer for correct symbol rendering
Prerequisites
Requires DejaVuSansMono Nerd Font for proper symbol display.
Prompt Structure
The default prompt layout is:
<branch git status><working directory>
Example output:
Installation
Clone the repository:
git clone https://git.x-files.dk/bash/bash-git-prompt.git ~/.bash-git-prompt
Install fonts:
cd ~/.bash-git-prompt
./install-fonts.sh
Add the following to your Bash configuration:
# Git Prompt Start
if [ -f "$HOME/.bash-git-prompt/bash-git-prompt" ]; then
export GIT_PROMPT_THEME=1
source "$HOME/.bash-git-prompt/bash-git-prompt"
fi
# Git Prompt Stop
Reload your environment:
source ~/.bashrc
Switching Themes
Change themes dynamically with:
gpchange <theme number>
Example:
gpchange 3
This updates the theme instantly for your current session.
Available Themes
Preview of all five themes (clean and dirty shown together for comparison):
Branch → Staged → Changed → Untracked → Stashed → Ahead → Behind → No-Remote → Conflict → Dirty → Clean
Terminal Font Setup
Set your terminal to use:
DejaVuSansMono Nerd Font Mono
Troubleshooting
Symbols not showing correctly:
Make sure your terminal uses DejaVuSansMono Nerd Font Mono.
Restart your terminal after installing fonts.
Log out and back in after installing fonts.
Prompt not loading:
Verify these lines exist and are correct in ~/.bashrc
:
# Git Prompt Start
if [ -f "$HOME/.bash-git-prompt/bash-git-prompt" ]; then
export GIT_PROMPT_THEME=1
source "$HOME/.bash-git-prompt/bash-git-prompt"
fi
# Git Prompt Stop
FAQ
Q: Does this replace my default prompt entirely?
A: No — the Git-aware segment only appears when your current directory is inside a Git repository.
Outside Git repos, your prompt remains normal (aside from minimal styling applied by the script).
To modify the non-Git prompt, edit this line in the script:
PS1='\u@\h:\[\e[38;5;178m\]\w\[\e[0m\] '"${PROMPT_CHAR} "
Q: Can I create my own theme?
A: Absolutely. Each theme is defined in the script under set_git_prompt_theme_icons()
.
You can modify or extend it, then set your new theme using export GIT_PROMPT_THEME=<number>
.
Q: Does it slow down Git-heavy directories?
A: Negligibly. The script uses optimized Git calls and caches status checks for performance.
More Information
More guides and documentation can be found on wiki.x-files.dk
License
Licensed under the MIT License.