11

I want to work with git, from the cmder powershell.

Errors

Cmder prints out the following error:

Missing git support, install posh-git with 'Install-Module posh-git' and restart cmder

If I run the Install-Module posh-git cmder prints out the next error:

  • Install-Module <<<< posh-git
    • CategoryInfo : ObjectNotFound: (Install-Module:String) [], CommandNotFoundException
    • FullyQualifiedErrorId : CommandNotFoundException

Things I have done/tried

Problem

My git commands are working, but not showing me the branch I am working on.

So how can I fix this?

Fabian Schmick
  • 1,616
  • 3
  • 23
  • 32
  • "Installed posh-git manually" <-- What did you do here? – Ryan Bemrose Mar 04 '16 at 21:19
  • Also, what version of PowerShell are you running? `Install-Module` requires 3.0 or later. – Ryan Bemrose Mar 04 '16 at 21:25
  • I followed the Installing (manual) guide for posh git here: [link](https://github.com/dahlbyk/posh-git) My PowerShell Version is Version 2.0 -> so I will try to update Powershell and run that command `Install-Module posh-git` again – Fabian Schmick Mar 04 '16 at 21:33
  • Possible duplicate of [The term 'Install-Module' is not recognized as the name of a cmdlet](http://stackoverflow.com/questions/29828756/the-term-install-module-is-not-recognized-as-the-name-of-a-cmdlet) – Ryan Bemrose Mar 04 '16 at 21:41
  • Your CommandNotFoundException is because `Install-Module` requires Powershell 3.0, or `PSGet` to be installed. However, the manual install should work. Verify that the file `posh-git.psm1` is located somewhere in `$env:PSModulePath`. – Ryan Bemrose Mar 04 '16 at 21:42
  • Also, on a whim, try restarting PowerShell after running `install.ps1`, if you haven't already. Then run `Import-Module posh-git` – Ryan Bemrose Mar 04 '16 at 21:43
  • I updated my Powershell and run the commend again, now it works just fine. Thank you for your help :) – Fabian Schmick Mar 04 '16 at 21:48

2 Answers2

22

This answer is for when posh-git is not wanted. posh-git can introduce significant delays to the prompt's display.

In the cmder profile (\vendor\profile.ps1) file, comment out the following lines in the function "checkGit".

function checkGit($Path) {
    #if (Test-Path -Path (Join-Path $Path '.git')) {
    #    $gitLoaded = Import-Git $gitLoaded
    #    Write-VcsStatus
    #    return
    #}

Note: Sorry, this answer doesn't answer the original request to see the current branch. I think that this solution may be a better fit for some people.

Update:

Here's a better solution that won't need to be reapplied every time that cmder is updated:

Add the following function to \config\user_profile.ps1 (the full path for my chocolatey installation file is c:\tools\cmdermini\config\user_profile.ps1):

function checkGit() {}

Josh
  • 2,142
  • 2
  • 23
  • 20
  • 2
    Yes, this is the answer I'm looking for. If you could change your code block from `` to `` it would be better. You can do this by adding 4 space before each line of code. And for convenience, use `<# ... #>`(powershell style comment block) instead of `#`. – Kyan Nov 19 '17 at 03:31
  • 1
    THANKYOU! This has been driving me nuts for months. – Kieron Mar 20 '19 at 07:57
  • Instead of disabling posh-git altogether, you can also `$GitPromptSettings.EnableFileStatus = $false` to turn off the `git status` check for every prompt without losing most tab expansion. – dahlbyk Jan 27 '20 at 20:18
6

Your CommandNotFoundException is because Install-Module requires Powershell 3.0, or PSGet to be installed. However, the manual install should work.

Verify that the file posh-git.psm1 is located somewhere in $env:PSModulePath. Then restart PowerShell and run Import-Module posh-git. This should force it to find the module.

Ryan Bemrose
  • 9,018
  • 1
  • 41
  • 54