Post navigation

Git bash

How to change the display name in Git bash

I share screen shots quite a lot in my blog posts and got fed up of needing to blur the user name information from my Git bash terminal screenshots. So I edited the shell prompt text in order to customise Git bash. Here are the steps you need to take in order to edit the git-prompt.sh file to hide the Git bash user name.

What is the git-prompt.sh file?

The git-prompt.sh file contains all of the configuration information for the Git bash terminal and the prompt itself.

If you open that file you will notice between lines 8 and 11 it does a test to see if a file exists here – ~/.config/git/git-prompt.sh and if it does then it loads the configuration data from there instead of this default file.

How to edit the git-prompt.sh file

  1. Find out where Git bash is installed on your system. You might need to search for gitbash.exe but on my system it was here – C:\Program Files\Git
  2. Now you want to navigate to the subfolder \etc\profile.d and find the file called git-prompt.sh. Open it in notepad or Vs Code as we are going to edit it.

Creating a custom configuration file

The ~ part of that file path refers to the folder relating to your username so it will be something like C:\Users\johndoe\. There was already a .config folder, so I created a git folder within that. You should then copy the default git-prompt.sh file from here:

C:\Program Files\Git\etc\profile.d

… and place the duplicate in the folder you just created at:

C:\Users\johndoe\.config\git

Now we can edit that file, leaving the original default version alone, and when you start Git bash from now on it will take the configuration from your new customised file. If you ever want to roll back to the original you can just delete your customised file and Git bash will revert to using the original, untouched file.

Editing the file to customise the text

We need to remove the if then else statement that looks for this custom file, otherwise Git bash will just crash when you try and run it. All I’ve done here is remove that block and then edit the cursor text to say brainstorm, so you could copy this text to use as the starting point for your custom file.

if test -f /etc/profile.d/git-sdk.sh
then
	TITLEPREFIX=SDK-${MSYSTEM#MINGW}
else
	TITLEPREFIX=$MSYSTEM
fi


	PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title
	PS1="$PS1"'\n'                 # new line
	PS1="$PS1"'\[\033[32m\]'       # change to green
	PS1="$PS1"'brainstorm '        # user@host<space> ----- this is where I have edited the name
	PS1="$PS1"'\[\033[35m\]'       # change to purple
	PS1="$PS1"'$MSYSTEM '          # show MSYSTEM
	PS1="$PS1"'\[\033[33m\]'       # change to brownish yellow
	PS1="$PS1"'\w'                 # current working directory
	if test -z "$WINELOADERNOEXEC"
	then
		GIT_EXEC_PATH="$(git --exec-path 2>/dev/null)"
		COMPLETION_PATH="${GIT_EXEC_PATH%/libexec/git-core}"
		COMPLETION_PATH="${COMPLETION_PATH%/lib/git-core}"
		COMPLETION_PATH="$COMPLETION_PATH/share/git/completion"
		if test -f "$COMPLETION_PATH/git-prompt.sh"
		then
			. "$COMPLETION_PATH/git-completion.bash"
			. "$COMPLETION_PATH/git-prompt.sh"
			PS1="$PS1"'\[\033[36m\]'  # change color to cyan
			PS1="$PS1"'`__git_ps1`'   # bash function
		fi
	fi
	PS1="$PS1"'\[\033[0m\]'        # change color
	PS1="$PS1"'\n'                 # new line
	PS1="$PS1"'$ '                 # prompt: always $

MSYS2_PS1="$PS1"               # for detection by MSYS2 SDK's bash.basrc

# Evaluate all user-specific Bash completion scripts (if any)
if test -z "$WINELOADERNOEXEC"
then
	for c in "$HOME"/bash_completion.d/*.bash
	do
		# Handle absence of any scripts (or the folder) gracefully
		test ! -f "$c" ||
		. "$c"
	done
fi

I’ll be following up with another post soon about how to customize the Git bash terminal colours. In the mean time you may find this post useful as it tells you how to change the default folder / directory in git bash, along with some other useful tips.