My git bash terminal how do i make my git bash terminal look like the below one. i want to display the current working directory and the current branch. my terminal use to look like the below one. but for some reason it is only showing "->". My friends git bash terminal please help me. i searched a lot for this question. i didn't find any answers.
-
1That's the `git-prompt`, part of the completion scripts. You'll want to install it to your environment. https://github.com/git/git/tree/master/contrib/completion. See also: https://stackoverflow.com/q/12399002/390278 – Jeff Mercado Nov 20 '20 at 06:32
-
1It also comes included with git for windows. You might want to try reinstalling the latest version again. – Jeff Mercado Nov 20 '20 at 06:36
-
How are you launching it? – Raman Sailopal Nov 20 '20 at 10:21
-
@RamanSailopal i am launching it normally. i click on git bash which is on my taskbar. – Manoj Nov 20 '20 at 10:56
-
@RamanSailopal please help me figure this out – Manoj Nov 20 '20 at 11:33
4 Answers
I'm on Windows and wanted to use git within MSYS2, not as a separate git bash terminal (which is what your friends seems to have). I downloaded Git for Windows and copied the following code from C:\Program Files\Git\etc\profile.d\git-prompt.sh into my bashrc file:
if test -f ~/.config/git/git-prompt.sh
then
. ~/.config/git/git-prompt.sh
else
PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[32m\]' # change to green
PS1="$PS1"'\u@\h ' # user@host<space>
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 $
fi
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
To do this, open an instance of MSYS2, open bashrc using any editor, for example with nano type nano ~/.bashrc
, scroll to the bottom of the file, and paste the above code in. New MSYS2 instances should look like your friend's!

- 31
- 1
Try this:
Paste in ~/.profile
or in ~/.bash_profile
:
git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
#update your prompt string
export PS1="[\u@\h \W]\\$\\$(git_branch)"
then source ~/.profile
or source ~/.bash_profile

- 3,872
- 6
- 22
- 37
This is what my prompt looks like:
Instead of showing the full path, it just shows the current branch and directory. It's designed with the file git-prompt.sh
which contains:
PS1='\[\033]0;$TITLEPREFIX:\W\007\]' # set window title
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[35m\]' # change to purple
PS1="$PS1"'git' # git user
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[33m\]' # change to brownish yellow
PS1="$PS1"'@\W' # current working directory
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[32m\]' # change to green
PS1="$PS1"'> ' # prompt: default $
PS1="$PS1"'\[\033[0m\]' # change color
To edit the git-prompt.sh
file, first go to your user profile folder. Example:
C:\Users\myProfile
Then go to the folder \.config\git
Example:
C:\Users\myProfile\.config\git
Then create or edit the git-prompt.sh
file, and paste in the code block above. The full path of git-prompt.sh
should be:
C:\Users\myProfile\.config\git\git-prompt.sh
For reference, the default git-prompt.sh
file is below:
if test -f /etc/profile.d/git-sdk.sh
then
TITLEPREFIX=SDK-${MSYSTEM#MINGW}
else
TITLEPREFIX=$MSYSTEM
fi
if test -f ~/.config/git/git-prompt.sh
then
. ~/.config/git/git-prompt.sh
else
PS1='\[\033]0;$TITLEPREFIX:$PWD\007\]' # set window title
PS1="$PS1"'\n' # new line
PS1="$PS1"'\[\033[32m\]' # change to green
PS1="$PS1"'\u@\h ' # user@host<space>
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 $
fi
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
The default git-prompt.sh
file may be found in any of the following folders:
C:\Users\myProfile\AppData\Local\Programs\Git\etc\profile.d\git-prompt.sh
C:\Program Files\Git\etc\profile.d\git-prompt.sh
Those can be edited directly instead of making a copy in your user profile. Editing those may change the prompt for all user profiles in your computer.

- 120
- 1
- 8
Git bash is like any other bash so just run pwd
(present working directory)
and for branch use git branch -a

- 163
- 1
- 9
-
i want my git terminal to look like this https://i.stack.imgur.com/QVJIw.png – Manoj Nov 20 '20 at 06:27