Show Git Branch and Status in Your Bash Prompt on Linux Mint
Social Share:
Sunday, August 9, 2026 at 12:00 AM | 9 min read
Last modified on Monday, August 10, 2026 at 4:46 PM
#macOS, #git, #linux, #linux mint, #command line

Photo by Kostas Dimopoulos on pexels.com
Table of Contents
- Git's native git-prompt.sh file
- Finding out which shell I use
- Where to find git-prompt.sh on Linux Mint
- What to do when git-prompt.sh or git-prompt is not found
- What GIT_PS1_SHOW* flag status symbols are and what they mean
- Verifying git-prompt customization in Linux at each stage
- Showing existing PS1 definitions already in my .bashrc
- Running a command to show the if/else structure around my color prompt block
- Searching specifically for Linux Mint's git-prompt file
- Backing up the .bashrc file before inserting git-prompt source lines
- Making sure the source lines landed where they were supposed to
- Opening the .bashrc file in Vim and manually editing it
- Testing the PS1 color edit made in .bashrc
- Running a fresh Terminal check to make sure my PS1 edits actually persisted
- Commands used in this post
- Conclusion
- Related Resources
- Related Posts
When I first set up Linux Mint in VirtualBox on my Dell laptop, I also added Git. However, the Git setup was minimal. Linux Mint's default bash setup does not display things like git branch/status information via a shell prompt integration out of the box. I could never imagine not having such features at my fingertips even for a millisecond! When I initialized a local Git repository, the command prompt did not display the Git branch, and the only way I could tell that the directory held a Git repo was by running git status. I was so used to a descriptive and colorful setup on my macOS. I finally decided to take the time to configure something similar in my Linux Mint OS.
Git's native git-prompt.sh file
After realizing the bare-bones setup of my Git configuration on Linux Mint, I was eager to add Git branch-display and status-indication to my Terminal command prompt.
I just found out that Git ships with a shell script called git-prompt.sh.
But what is git-prompt.sh?
git-prompt.sh is a native Git shell script which is meant for bash users like myself, in Linux in this instance, to enhance my command line experience while working inside my Git repositories. I can customize the git-prompt.sh file to display relevant information about the Git repository I am working on. For example, it lets me display the current Git branch name and working directory status. It's meant to be sourced from my shell startup file (.bashrc) so the prompt updates automatically while I work inside my repository.
git-prompt.sh provides a specialized function called __git_ps1 that automatically extracts and formats this information whenever I navigate into a local Git repository on my machine.
Finding out which shell I use
I know that I use bash in Linux Mint. But let's say I didn't know. I would run
echo $SHELL
in my Linux Terminal to find out. For me, Terminal returned:
/bin/bash
This means that I am using Bash.
Where to find git-prompt.sh on Linux Mint
Generally, to find git-prompt.sh on Linux, I would run:
find / -name "git-prompt.sh" 2>/dev/null
However, I am on Linux Mint, and the name of the file is slightly different. So I would run
find / -name "git-prompt" 2>/dev/null
which, for me, yielded:
/etc/bash_completion.d/git-prompt
What to do when git-prompt.sh or git-prompt is not found
If, for whatever reason, you don't find your git-prompt.sh or git-prompt file, do the following:
echo $SHELL find / -name "git-prompt.sh" 2>/dev/null
find / -name "git-prompt.sh" means find a file called git-prompt.sh from within the top-level root (/) directory down. 2>/dev/null means redirect any error messages to the special file called /dev/null, which discards them. This means that any error messages generated by the find command will not display in Terminal.
2 stands for the standard error (stderr) file descriptor in Unix-like systems. 0 stands for standard input (stdin) and 1 stands for standard output (stdout).
> is the output redirection operator. It tells the shell to redirect output from one location to another. To learn more about redirect operators, please visit my post entitled Redirect operators in Linux and Unix (macOS).
Usually git-prompt.sh already exists at /usr/lib/git-core/git-prompt.sh or /etc/bash_completion.d/git-prompt on Debian-based distros like Linux Mint.
If you don't find git-prompt.sh, you can download it using the curl command:
curl -o ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh
Then open your ~/.bashrc file:
vim ~/.bashrc # or nano ~/.bashrc
Scroll to the bottom of ~/.bashrc and add the following:
# Git branch/status in prompt if [ -f ~/.git-prompt.sh ]; then source ~/.git-prompt.sh elif [ -f /usr/lib/git-core/git-prompt.sh ]; then source /usr/lib/git-core/git-prompt.sh fi export GIT_PS1_SHOWDIRTYSTATE=1 export GIT_PS1_SHOWSTASHSTATE=1 export GIT_PS1_SHOWUNTRACKEDFILES=1 export GIT_PS1_SHOWUPSTREAM="auto" export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;33m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '
The if/elif sourcing handles either location depending on where it ended up.
Then reload your ~/.bashrc file:
source ~/.bashrc
Next, test your customization:
cd ~/projects/file-organization-app # or wherever it lives locally
You should see something like:
maria@maria-VirtualBox:~/projects/file-organization-app (main)$
It'll flag * for uncommitted changes, $ for stash, % for untracked files, depending on which flags you enabled.
What GIT_PS1_SHOW* flag status symbols are and what they mean
The GIT_PS1_SHOW* flags are environment variables used to customize the output of the Git prompt in Terminal. They control what information is displayed.
GIT_PS1_SHOW* flags include:
* - Unstaged changes (modified files not added)
+ - Staged changes (files added but not committed)
$ - Stashed changes exist
% - Untracked files present
< - Behind upstream branch
> - Ahead of upstream branch
<> - Diverged from upstream
= - Equal to upstream
Verifying git-prompt customization in Linux at each stage
Showing existing PS1 definitions already in my .bashrc
To show any existing PS1 definitions in my .bashrc, I ran:
# check the current state of PS1 grep -n "PS1" ~/.bashrc
And it returned:
# grep -n "PS1" ~/.bashrc output: 60: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' 62: PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' 69: PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
Lines 60, 62, and 69 are the standard Debian/Ubuntu-family default .bashrc structure that Mint inherited:
- Line 60: sets PS1 with colors, used when the terminal supports color
- Line 62: sets PS1 without colors, used as a fallback
- Line 69: runs after one of those, and prepends a terminal title-bar escape sequence, but it does $PS1 at the end, meaning it wraps whatever line 60 or 62 already are set, it doesn't replace either line.
The correct approach to customizing PS1, per the git-prompt.sh file, is to modify line 60 and line 62 directly, not add a separate block elsewhere. This is so the git branch information is baked into the same PS1 that's already correctly wired into Mint's conditional logic.
Running a command to show the if/else structure around my color prompt block
To find the if/else structure around my color prompt block in my .bashrc file, I ran:
sed -n '40,70p' ~/.bashrc
According to man sed:
The sed utility reads the specified files, or the standard input if no files are specified, modifying the input as specified by a list of commands. The input is then written to the standard output.
The -n flag suppresses seds default echo of each line of input to the standard output after all of the commands have been applied to it.
'40,70p' points to line 40 and 70 in .bashrc. So sed -n '40,70p' ~/.bashrc prints out the lines 40-70 of .bashrc to Terminal:
sed -n '40,70p' ~/.bashrc: xterm-color|*-256color) color_prompt=yes;; esac # uncomment for a colored prompt, if the terminal has the capability; turned # off by default to not distract the user: the focus in a terminal window # should be on the output of commands, not on the prompt #force_color_prompt=yes if [ -n "$force_color_prompt" ]; then if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then # We have color support; assume it's compliant with Ecma-48 # (ISO/IEC-6429). (Lack of such support is extremely rare, and such # a case would tend to support setf rather than setaf.) color_prompt=yes else color_prompt= fi fi if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi unset color_prompt force_color_prompt # If this is an xterm set the title to user@host:dir case "$TERM" in xterm*|rxvt*) PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
This way, I was able to precisely determine which lines to edit regarding PS1 and could therefore edit the file in-place. I also learned that appending anything after line 69 would be fine, but anything that needed to be sourced before it executed in order, not just exist in the file, or if the source line landed after line 69 but referenced functions not yet loaded, or if Nano/Vim saved the if/else block in the wrong place, I'd get a result that worked within a live session but would not persist beyond it.
Searching specifically for Linux Mint's git-prompt file
All the previous information I provided was general to Linux and generally-specific to Linux Mint. But from this point on, I specifically discuss what I did to show Git branch and Git status in my Git repositories' command prompts. From this point on might be much more helpful to you because it includes the steps that actually took place within my VirtualBox Linux Mint OS.
And because running find / (from root down) can (potentially) take painstakingly long, I ran
dpkg -L git | grep git-prompt
to find out where git-prompt resided. However, it returned nothing. But the command didn't find a package literally named "git", not that "git-prompt" didn't exist.
So next, I ran a command that told me where git was installed:
which git
which git returned:
/usr/bin/git
Then I ran:
dpkg -S $(which git)
The above command would tell me the exact package name. Then I could use the dpkg package manager to list all files it installed and find git-prompt.sh directly. This would be much faster than a filesystem-wide search.
dpkg -S $(which git) provided:
git: /usr/bin/git
which confirmed what I had already queried.
Now that I had confirmed the definite package name, I ran:
dpkg -L git | grep git-prompt
This command asks the dpkg package manager directly which files the git package installed. And it returned:
/etc/bash_completion.d/git-prompt
It returned the location of the git-prompt file I was looking for!
Backing up the .bashrc file before inserting git-prompt source lines
Next, I ran a command to backup my .bashrc file in case if something went wrong:
cp ~/.bashrc ~/.bashrc.backup
Then I inserted the git-prompt source lines before the if [ "$color_prompt" = yes ] statement in .bashrc:
sed -i '/^if \[ "\$color_prompt" = yes \]; then$/i\ source /etc/bash_completion.d/git-prompt\ export GIT_PS1_SHOWDIRTYSTATE=1\ export GIT_PS1_SHOWSTASHSTATE=1\ export GIT_PS1_SHOWUNTRACKEDFILES=1\ export GIT_PS1_SHOWUPSTREAM="auto"' ~/.bashrc
I just had to make sure that I pasted the whole sed -n '55,75p' ~/.bashrc block altogether, not one line at a time.
Making sure the source lines landed where they were supposed to
Then, to make sure the source lines landed in the right place, I ran:
sed -n '55,75p' ~/.bashrc
This command yielded:
color_prompt= fi fi source /etc/bash_completion.d/git-prompt export GIT_PS1_SHOWDIRTYSTATE=1 export GIT_PS1_SHOWSTASHSTATE=1 export GIT_PS1_SHOWUNTRACKEDFILES=1 export GIT_PS1_SHOWUPSTREAM="auto" if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' fi unset color_prompt force_color_prompt # If this is an xterm set the title to user@host:dir case "$TERM" in xterm*|rxvt*) PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
This was verification that the five lines placed with the sed -i '/^if \[ "\$color_prompt" = yes \]; command landed right before the if [ "$color_prompt" = yes ]; then block, and the __git_ps1 function will now be defined by the time PS1 is built.
Opening the .bashrc file in Vim and manually editing it
Next, I ran the vim ~/.bashrc command and made the ensuing edits:
# First I changed: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ ' # to: PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;33m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ ' # then I changed: PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' # to: PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 " (%s)")\$ ' # then I pressed the esc key followed by the Shift + Colon key, then the x key and finally pressed the return key.
I needed to confirm that my edits were correct, so I ran:
sed -n '60,70p' ~/.bashrc
This came back with:
export GIT_PS1_SHOWDIRTYSTATE=1 export GIT_PS1_SHOWSTASHSTATE=1 export GIT_PS1_SHOWUNTRACKEDFILES=1 export GIT_PS1_SHOWUPSTREAM="auto" if [ "$color_prompt" = yes ]; then PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;33m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ ' else PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(__git_ps1 " (%s)")\$ ' fi unset color_prompt force_color_prompt
Both lines I edited matched the color scheme I wanted. The color scheme had \[\033[01;33m\]$(__git_ps1 " (%s)")\[\033[00m\] and the fallback plain scheme had $(__git_ps1 " (%s)"). The two edited lines survived the insert and were intact.
Testing the PS1 color edit made in .bashrc
To make sure that I made my PS1 color edit correctly, first I had to remember the name of the sole Git repository I had in my Linux Mint OS. To do that without relying on my memory, I ran:
find ~ -maxdepth 4 -name ".git" -type d 2>/dev/null
I searched for a directory called ".git" within my home directory (~) four levels deep. The command came back with:
/home/maria/Desktop/python-files/file-organization-app/.git
When I cd into the repository, the following appeared:
~/Desktop/python-files/file-organization-app (main *)$
The * meant that I had unstaged changes in my local Git repository. Loved it already. Don't have this kind of set up on macOS. But since I do have the Oh My Zsh theme there, I could (and will) customize a similar setup. It's nice to know what is going on in your local repository before you even run any Git commands!
My PS1 customization enabled the symbols below:
- * — unstaged changes (git status, working directory has modifications not yet staged)
- + — staged changes (added with git add, not yet committed)
- $ — a stash exists (git stash)
- % — untracked files present (git status, new files Git doesn't know about yet)
- <, >, <>, = — behind, ahead, diverged, or in sync with the upstream branch (typically main)
Running a fresh Terminal check to make sure my PS1 edits actually persisted
I wanted to make absolutely sure that my PS1 edits actually persisted, so I opened a completely new Terminal window (not a tab) and cd into my file-organization-app Git repository. The edits stuck!
Commands used in this post
| Command | Purpose |
|---|---|
| echo $SHELL | Tells me what shell I am on. |
| find / -name "git-prompt.sh" 2>/dev/null | Finds git-prompt.sh on Linux |
| find / -name "git-prompt" 2>/dev/null | Finds git-prompt on Linux Mint |
| curl -o ~/.git-prompt.sh https://raw.githubusercontent.com/git/git/master/contrib/completion/git-prompt.sh | Downloads git-prompt.sh for Linux |
| vim ~/.bashrc or nano ~/.bashrc | Opens ~/bashrc in Vim or Nano editor |
| source ~/.bashrc | Reloads Bash settings and applies changes immediately in the current Bash session |
| grep -n "PS1" ~/.bashrc | Shows any existing PS1 definitions in my .bashrc |
| sed -n '40,70p' ~/.bashrc | Returns lines 40-70 of my ~/.bashrc file |
| dpkg -L git | grep git-prompt | Locates installed file path |
| which git | Tells me the path where Git resides |
| dpkg -S $(which git) | Tells me both the package name and where it's located |
| cp ~/.bashrc ~/.bashrc.backup | Backs up my .bashrc file |
| sed -n '55,75p' ~/.bashrc | Returns lines 55-75 of my ~/.bashrc file |
| sed -n '60,70p' ~/.bashrc | Returns lines 60-70 of my ~/.bashrc file |
| find ~ -maxdepth 4 -name ".git" -type d 2>/dev/null | Searches for a ".git" directory in home directory (~) four levels deep |
Conclusion
In this post, I walk through how to enhance the Git version control experience in Linux Mint. By default, Linux Mint does not visually indicate whether a directory is a Git repository. I had to edit my .bashrc file with GIT_PS1_SHOW* flags to customize the output of the Git prompt and $PS1 color environment variables to colorize it. What I found appealing about the Git Bash configuration was that it was a very different experience than zsh on macOS. Not worse. Just different. And in some ways, more informative because it tells me what's up with my Git repository without my having to run commands such as git status, git stash list, etc.
Related Resources
- Making the Linux Shell Prompt more Git Friendly: technotes.ryanbrownell.com
- A1.6 Appendix A: Git in Other Environments - Git in Bash: git-scm.com
- Git Prompt Variables: backslasher.net
- Show Git Branch & Status in Bash Prompt: glukhov.org
Related Posts
- Coordinating Git Pushes Between macOS and Linux Mint: mariadcampbell.com