I was messing around with the color codes trying to understand how color code is used in bash script and I found that it works fine without including \[\] around it as in here:
This..
red="\033[38;5;203m"
export PS1="$red\u$green\$(__git_ps1)$blue \W"
..gives the same result as that:
red="\[\033[38;5;203m\]"
export PS1="$red\u$green\$(__git_ps1)$blue \W"
So is the second form necessary?