Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions book/A-git-in-other-environments/sections/powershell.asc
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
(((powershell)))(((tab completion, powershell)))(((shell prompts, powershell)))
(((posh-git)))
The legacy command-line terminal on Windows (`cmd.exe`) isn't really capable of a customized Git experience, but if you're using PowerShell, you're in luck.
This also works if you're running PowerShell on a non-Windows platform like Debian.
A package called Posh-Git (https://github.com/dahlbyk/posh-git[]) provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repository status.
This also works if you're running PowerShell Core on Linux or macOS.
A package called posh-git (https://github.com/dahlbyk/posh-git[]) provides powerful tab-completion facilities, as well as an enhanced prompt to help you stay on top of your repository status.
It looks like this:

.PowerShell with Posh-git.
Expand All @@ -27,16 +27,15 @@ More about PowerShell ExecutionPolicy: https://docs.microsoft.com/en-us/powershe
-----

===== PowerShell Gallery
If you have at least PowerShell 5 or PowerShell 4 with PackageManagement installed, you can use the package manager to fetch Posh-Git for you.
If you have at least PowerShell 5 or PowerShell 4 with PackageManagement installed, you can use the package manager to install posh-git for you.

More information about PowerShell Gallery: https://docs.microsoft.com/en-us/powershell/gallery/overview[]
[source,powershell]
-----
> Set-PSRepository -Name PSGallery -InstallationPolicy Trusted
> Update-Module PowerShellGet -Force
> Install-Module Posh-Git -Scope AllUsers
> Install-Module posh-git -Scope CurrentUser -Force
> Install-Module posh-git -Scope CurrentUser -AllowPrerelease -Force # Newer beta version with PowerShell Core support
-----
If you want to install Posh-Git only for the current user and not globally, use "-Scope CurrentUser" instead.
If you want to install posh-git for all users, use "-Scope AllUsers" instead and execute the command from an elevated PowerShell console.
If the second command fails with an error like `Module 'PowerShellGet' was not installed by using Install-Module`, you'll need to run another command first:

[source,powershell]
Expand All @@ -48,21 +47,23 @@ Then you can go back and try again.
This happens, because the modules that ship with Windows PowerShell are signed with a different publishment certificate.

===== Update PowerShell Prompt
To include git information in your prompt, posh-git needs to be imported. To do this automatically, include the import statement into you $profile script. This script is executed everytime you open a new PowerShell prompt.
To include git information in your prompt, the posh-git module needs to be imported. To have posh-git imported every time PowerShell starts, execute the Add-PoshGitToProfile command which will add the import statement into you $profile script. This script is executed everytime you open a new PowerShell console.
Keep in mind, that there are multiple $profile scripts. E. g. one for the console and a separate one for the ISE.
[source,powershell]
-----
> New-Item -Name $(Split-Path -Path $profile) -ItemType Directory -Force
> 'Import-Module Posh-Git' | Out-File -Append -Encoding default -FilePath $profile
> Import-Module posh-git
> Add-PoshGitToProfile -AllHosts
-----

===== From Source
Just download a Posh-Git release from (https://github.com/dahlbyk/posh-git[]), and uncompress it to the `WindowsPowerShell` directory.
Then open a PowerShell prompt as an administrator, and do this:
Just download a posh-git release from (https://github.com/dahlbyk/posh-git[]), and uncompress it.
Then import the module using the full path to the posh-git.psd1 file:
[source,powershell]
-----
> cd ~\Documents\WindowsPowerShell\Module\posh-git
> .\install.ps1
> Import-Module <path-to-uncompress-folder>\src\posh-git.psd1
> Add-PoshGitToProfile -AllHosts
-----

This will add the proper line to your `profile.ps1` file, and posh-git will be active the next time you open your prompt.
This will add the proper line to your `profile.ps1` file, and posh-git will be active the next time you open PowerShell.
For a description of the Git status summary information displayed in the prompt see: https://github.com/dahlbyk/posh-git/blob/master/README.md#git-status-summary-information[]
For more details on how to customize your posh-git prompt see: https://github.com/dahlbyk/posh-git/blob/master/README.md#customization-variables[]
Binary file modified images/posh-git.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.