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 part of the command prompt.
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 part of the command prompt.
@Paul-
My PowerShell profile for Git is based off of a script I found here:
http://techblogging.wordpress.com/2008/10/12/displaying-git-branch-on-your-powershell-prompt/
I've modified it a bit to display the directory path and a bit of formatting. It also sets the path to my Git bin location since I use PortableGit.
So far, this has worked really well. While in a repo, the prompt happily looks like:
GIT [master] c:0 u:1 d:0 | J:\Projects\forks\fluent-nhibernate>
*NOTE: Updated with suggestions from Jakub Narębski.
I tweaked the prompt code (from @david-longnecker answer) to be a bit more colorful.
Edit: Oct 2018 - Reworked with additional comments, some cleanup, a less noisy output than before.
The powershell code:
The result (VSCode, Using Powershell terminal):
Here are commands from result to view what it would look like:
An easier way would be just installing the Powershell module posh-git. It comes out of the box with the desired prompt:
(For installing posh-git I suggest using psget)
If you don't have psget use the following command:
To install posh-git use the command:
Install-Module posh-git
To ensure posh-git loads for every shell, use the
Add-PoshGitToPrompt
command.Here's my take on it. I've edited the colours a bit to make it more readable.
Microsoft.PowerShell_profile.ps1
Example 1:
Example 2: