Conda environment name hides git branch after conda init in Powershell

Viewed 157

I have the Posh-Git module installed for Powershell and, recently, I also installed Anaconda and did conda init. Apparently, this modifies the profile.ps1 file by adding the following code:

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "{User}\anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion

This does let me see the conda environment I'm working with but it also hides the Git branch I'm working on. How do I modify this so that I can see both?

1 Answers

The posh-git docs state that posh-git won't modify a custom prompt. So when you run Import-Module posh-git after conda has initialized, you won't see anything change. The solution is to put Import-Module posh-git before the conda initialization block in your $Profile.CurrentUserAllHosts file so it looks like:

Import-Module posh-git

#region conda initialize
# !! Contents within this block are managed by 'conda init' !!
(& "{User}\anaconda3\Scripts\conda.exe" "shell.powershell" "hook") | Out-String | Invoke-Expression
#endregion

It's worth also noting that when you run Add-PoshGitToProfile, it adds the Import-Module posh-git line to your $Profile.CurrentUserCurrentHost file. Since this executes after $Profile.CurrentUserAllHosts, that command will not have any noticeable effect.

Related