How can I display my current git branch name in my PowerShell prompt?

前端 未结 7 2106
暗喜
暗喜 2020-11-30 20:18

Basically I\'m after this but for PowerShell instead of bash.

I use git on windows through PowerShell. If possible, I\'d like my current branch name to displayed as

7条回答
  •  悲&欢浪女
    2020-11-30 20:54

    I like the accepted answer so I will elaborate on the steps to set it up. You can install PoshGit using Chocolatey or using the PowerShellGet command which is available for the new Core PowerShell.

    For Chocolatey, you need to have it already installed before proceeding. In an administrator/elevated shell execute the command:

    choco install poshgit
    

    For Core PowerShell, installation is also required. To install Core PowerShell, execute the following command:

    dotnet tool install --global PowerShell
    

    NB: You need to have .NET Core SDK installed (latest version preferably)

    After installing Core PowerShell, execute the command below to install PoshGit:

    PowerShellGet\Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force
    

    Using PoshGit requires you import it to the currently running shell environment using the command Import-Module posh-git. This means you have to run this command every time you open a new shell.

    If you want PoshGit to be always available you should execute this command instead:

    Add-PoshGitToProfile
    

    Please note that PowerShell and Core PowerShell are different and as a result they run on different profiles. What this means is that if you want PoshGit to work for either of the shells you need to execute those commands in their respective shell environment.

提交回复
热议问题