Using posh-git and posh-hg together

I use both Git and Mercurial for projects, as well as Powershell as a console for both. Both source control systems have awesome plugins in posh-git and posh-hg that provide nice statuses, tab expansions and so on. However, they don’t just automatically play nice with one another. I installed Github for Windows, and found that my posh-hg stuff went away.

However, thanks to this Stack Overflow answer, it’s easy to use both of these together. I cloned both repositories to my local box, and then just modified the script to point to that version:

function isCurrentDirectoryARepository($type) {

    if ((Test-Path $type) -eq $TRUE) {
        return $TRUE

    # Test within parent dirs
    $checkIn = (Get-Item .).parent
    while ($checkIn -ne $NULL) {
        $pathToTest = $checkIn.fullname + '/' + $type;
        if ((Test-Path $pathToTest) -eq $TRUE) {
            return $TRUE
        } else {
            $checkIn = $checkIn.parent
    return $FALSE

# Posh-Hg and Posh-git prompt
# Change this to point to wherever your two profile scripts are

. 'C:\dev\posh-hg\profile.example.ps1'
. 'C:\dev\posh-git\profile.example.ps1'

function prompt(){
    # Reset color, which can be messed up by Enable-GitColors
    $Host.UI.RawUI.ForegroundColor = $GitPromptSettings.DefaultForegroundColor

    Write-Host($pwd) -nonewline

    if (isCurrentDirectoryARepository(".git")) {
        # Git Prompt
        $Global:GitStatus = Get-GitStatus
        Write-GitStatus $GitStatus
    } elseif (isCurrentDirectoryARepository(".hg")) {
        # Mercurial Prompt
        $Global:HgStatus = Get-HgStatus
        Write-HgStatus $HgStatus

    return "> "

Now I get both posh-hg and posh-git working together!

About Jimmy Bogard

I'm a technical architect with Headspring in Austin, TX. I focus on DDD, distributed systems, and any other acronym-centric design/architecture/methodology. I created AutoMapper and am a co-author of the ASP.NET MVC in Action books.
This entry was posted in git, Mercurial. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Anonymous

    I wish someone could port these to a UNIX environment. I have a script running in my mac but it isn’t as nice as posh-hg or posh-git.

  • Jimmy, this is all is bit outdated, latest version of the posh-git and posh-hg works together without any problems. They adopted single Write-VcsStatus , with some powershell magic they managed to resolve conflicts. You probably just need to update your Posh-Hg (assuming that git for windows distributes last Posh-Git)

    Checkout my profile.ps1 –

    • To make things clear.
      . ‘C:devposh-hgprofile.example.ps1′
      . ‘C:devposh-gitprofile.example.ps1′

      This two lines is enough in your case, you can inspect this files to get an idea.