How to get branch names to appear in the VS Code integrated terminal?

8,378

The problem is not VS code because you're actually looking at your terminal.

You simply have to edit the settings that define how your terminal appears.

If you're on MacOS Catalina, then you can edit the ~/.zshrc file.

This should be the code that you need-

parse_git_branch() {
    git branch 2> /dev/null | sed -n -e 's/^\* \(.*\)/[\1]/p'
}
COLOR_DEF=$'\e[0m'
COLOR_USR=$'\e[38;5;243m'
COLOR_DIR=$'\e[38;5;197m'
COLOR_GIT=$'\e[38;5;39m'
NEWLINE=$'\n'
setopt PROMPT_SUBST
export PROMPT='${COLOR_DIR}%d ${COLOR_GIT}$(parse_git_branch)${COLOR_DEF}%% '
Share:
8,378
Cauder
Author by

Cauder

Updated on September 18, 2022

Comments

  • Cauder
    Cauder over 1 year

    I recently installed a new instance of VS Code on my Mac and the integrated terminal no longer shows the current branch.

    In the old world, it would show which branch I was on right now with git and update as I changed branches.

    Now, it shows my location in the file directory and git works as normal but it doesn't show the branch.

    I have no extensions except for GitHistory. This is an excerpt from my settings file:

    {
        "workbench.statusBar.visible": false,
        "explorer.decorations.colors": false,
        "window.zoomLevel": 0,
        "workbench.startupEditor": "newUntitledFile",
        "workbench.editor.closeOnFileDelete": true,
        "workbench.editor.limit.enabled": true,
        "workbench.editor.openPositioning": "first",
        "python.linting.pylintEnabled": true,
        "python.linting.enabled": true,
        "terminal.integrated.scrollback": 50000,
        "terminal.integrated.shell.osx": ""
    }
    
    • harrymc
      harrymc almost 4 years
      The update may have switched your integrated terminal shell from Git Bash to Powershell . You can check that in menu File > Preferences > Shell.
    • Cauder
      Cauder almost 4 years
      Added the shell settings. It looks like it's not set to anything
    • harrymc
      harrymc almost 4 years
      In Windows you would add "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe". I don't know the Mac equivalence.