I use Vscode, and I want to know Where my HEAD is pointing branch,
How Can I show up the current branch name like Bash?
I use WSL(ubuntu)termimal in my Vscode and OS is Windows 10
Thank you
I use Vscode, and I want to know Where my HEAD is pointing branch,
How Can I show up the current branch name like Bash?
I use WSL(ubuntu)termimal in my Vscode and OS is Windows 10
Thank you
Note that, from microsoft/vscode
issue 67670, the current branch name is already visible in the status bar of VSCode.
Or, with Git 2.22+ (Q2 2019)
git branch --show-current
It is true the prompt in a git bash in VSCode does not display the Git branch.
You need to configure the $SHELL
For example, to enable running bash as a login shell (which runs
.bash_profile
), pass in the-l
argument (with double quotes):
// Linux
"terminal.integrated.shellArgs.linux": ["-l"]
Then in your ~/.bashrc
can include a special prompt.
I got it configured by modifying the .bashrc file in the /home/ on the WSL session. You can do vim ~/.bashrc to edit the file.
Find and replace the code block in the .bashrc with this;
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\$(`git branch --show-current 2>/dev/null`)\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$(`git branch --show-current 2>/dev/null`)\$ '
fi
I found @Diganto Paul's answer does not show the current directory (as it was by default). I used this instead:
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\]\$ '
Copied from: https://hinty.io/ivictbor/show-git-branch-in-bash-on-linux-windows-wsl-2-cygwin-prompt/