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.
Asked
Active
Viewed 1,160 times
-2
-
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
3 Answers
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
dejanualex
- 3,175
- 6
- 21
- 31
1
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!
Tachy0n1c
- 11
- 1
-1
Git bash is like any other bash so just run pwd (present working directory)
and for branch use git branch -a
Mohak Gupta
- 145
- 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