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

前端 未结 7 2111
暗喜
暗喜 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:53

    An easier way would be just installing the Powershell module posh-git. It comes out of the box with the desired prompt:

    The Prompt

    PowerShell generates its prompt by executing a prompt function, if one exists. posh-git defines such a function in profile.example.ps1 that outputs the current working directory followed by an abbreviated git status:

    C:\Users\Keith [master]>

    By default, the status summary has the following format:

    [{HEAD-name} +A ~B -C !D | +E ~F -G !H]

    (For installing posh-git I suggest using psget)

    If you don't have psget use the following command:

    (new-object Net.WebClient).DownloadString("http://psget.net/GetPsGet.ps1") | iex
    

    To install posh-git use the command: Install-Module posh-git

    To ensure posh-git loads for every shell, use the Add-PoshGitToProfile command.

提交回复
热议问题