如何在 WSL 中显示当前分支(我使用 Vscode)

How do I show up the current branch in WSL ( I use Vscode)

我使用 Vscode,我想知道我的 HEAD 指向哪里分支,
如何显示当前分支名称,如 Bash?
我在 Vscode 中使用 WSL(ubuntu)termimal 并且 OS 是 Windows 10

谢谢

请注意,从microsoft/vscode issue 67670开始,当前分支名称已经在VSCode的状态栏中可见。

或者,with Git 2.22+(2019 年第 2 季度)

git branch --show-current

prompt in a git bash in VSCode does not display the Git branch 是真的。

你需要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"]

然后在你的~/.bashrc中可以include a special prompt.

我通过修改 WSL 会话中 /home/ 中的 .bashrc 文件来配置它。您可以执行 vim ~/.bashrc 来编辑文件。

在 .bashrc 中查找并替换代码块;

if [ "$color_prompt" = yes ]; then
        PS1='${debian_chroot:+($debian_chroot)}\[3[01;32m\]\u@\h\[3[00m\]:\[3[01;34m\]$(`git branch --show-current 2>/dev/null`)\[3[00m\]$ '
else
        PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w$(`git branch --show-current 2>/dev/null`)$ '
fi