Coloring your Posh-Git output

As a followup to my previous post, Coloring your Git output, if you use Posh-Git you can also edit the colors of the Git output by modifying the Posh-Git settings.

What is Posh-Git? It’s a fantastic set of Powershell scripts for Git. It provides tab completion plus information right in the prompt stating the currently checked out branch along with the working copy and index statuses.

The Posh-Git color settings can be changed using the $global:GitPromptSettings object. Here are the available properties you can set:

  • IndexForegroundColor
  • BranchForegroundColor
  • BranchAheadBackgroundColor
  • AfterBackgroundColor
  • BranchBehindForegroundColor
  • UntrackedBackgroundColor
  • AfterText
  • BeforeForegroundColor
  • WorkingForegroundColor
  • RepositoriesInWhichToDisableFileStatus
  • EnableWindowTitle
  • ShowStatusWhenZero
  • BeforeIndexForegroundColor
  • BeforeIndexBackgroundColor
  • BranchBackgroundColor
  • DescribeStyle
  • BeforeBackgroundColor
  • WorkingBackgroundColor
  • DelimText
  • UntrackedForegroundColor
  • DefaultForegroundColor
  • AfterForegroundColor
  • DelimBackgroundColor
  • Debug
  • BeforeIndexText
  • BranchAheadForegroundColor
  • DelimForegroundColor
  • UntrackedText
  • EnableFileStatus
  • IndexBackgroundColor
  • AutoRefreshIndex
  • BeforeText
  • BranchBehindAndAheadBackgroundColor
  • BranchBehindBackgroundColor
  • BranchBehindAndAheadForegroundColor
  • EnablePromptStatus

You have a few more color options than the 9 that Git allow as well:

  • Black
  • Blue
  • Cyan
  • DarkBlue
  • DarkCyan
  • DarkGray
  • DarkGreen
  • DarkMagenta
  • DarkRed
  • DarkYellow
  • Gray
  • Green
  • Magenta
  • Red
  • White
  • Yellow

You can edit these by editing Posh-Git’s GitPrompt.ps1 file although it’s not recommended. If (and when) you update Posh-Git those settings will be overwritten. The better way is to edit your profile settings to set the colors on startup. Calling $profile at the Powershell prompt will display the location of your profile file; open it to edit your Powershell profile. You’ll see a line in there that initializes Posh-Git:

. 'C:\tools\poshgit\dahlbyk-posh-git-c481e5b\profile.example.ps1'

You should place any customizations after that line:

$global:GitPromptSettings.WorkingForegroundColor = [ConsoleColor]::Yellow 
$global:GitPromptSettings.UntrackedForegroundColor = [ConsoleColor]::Yellow

Now git nuts!