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\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\[\033[33m\]$(parse_git_branch)\[\033[00m\]\$ ' |
The solution will work for WSL 2 or mintty
terminal from Cygwin: and will not work on Windows native cmd
. This will look like this: