If you use Windows PowerShell, you can override the standard Hint function by running the following in the PowerShell window that you are using. This will force it to detect Git repositories and list the Git branch at the prompt:
Function Prompt { $git_cmd = "git rev-parse --abbrev-ref HEAD" Invoke-Expression $git_cmd 2> $null | Tee-Object -Variable git_branch | Out-Null $git_branch_text = $None if ( $git_branch -And -Not $git_branch.StartsWith($git_cmd)) { $git_branch_text = "[$git_branch] " } $stringBuilder = New-Object System.Text.StringBuilder $null = $stringBuilder.Append("PS ") if ($git_branch_text) { $null = $stringBuilder.Append($git_branch_text) } $null = $stringBuilder.Append($($executionContext.SessionState.Path.CurrentLocation)) $null = $stringBuilder.Append($('>' * ($nestedPromptLevel + 1))) $null = $stringBuilder.Append(" ") return $stringBuilder.ToString() } PS C:\Users\username\Document\GitHub> PS C:\Users\username\Document\GitHub>cd code_repository PS [dev] C:\Users\username\Document\GitHub\code_repository> PS [dev] C:\Users\username\Document\GitHub\code_repository>cd .. PS C:\Users\username\Document\GitHub>
Tested in PowerShell version 5.1.17763.592.
To apply this prompt change in all of your PowerShell command windows, put this function in a file called profile.ps1 in C: \ Users \ username \ Documents \ WindowsPowerShell . Any PowerShell command windows that open after this must have a Git prompt in a directory that is part of the Git repository.
Dococ source share