Show git branch in bash on linux/windows WSL 2/cygwin prompt

Open file ~/.bashrc , e.g.

nano ~/.bashrc

If you have no nano use:

apt install nano

Add to the end of the file:

parse_git_branch() {
   git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\[email protected]\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[33m\]$(parse_git_branch)\[\033[00m\]\$ '

The solution will work only for mintty building Cygwin terminal: and will not work on windows cmd. This will look like this:

Show git branch

#cygwin #wsl
menu 0
Ivan Borshchov profile picture
Dec 08, 2016
by Ivan Borshchov
Did it help you?
Yes !
No

Best related

Other by Ivan Borshchov