posh-git

posh-git is a PowerShell module that integrates Git and PowerShell by providing Git status summary information that can be displayed in the PowerShell prompt, e.g.:

C:\Users\Keith\GitHub\posh-git [master ≡ +0 ~1 -0 !]>

posh-git also provides tab completion support for common git commands, branch names, paths and more. For example, with posh-git, PowerShell can tab complete git commands like checkout by typing git ch and pressing the tab key. That will tab complete to git checkout and if you keep pressing tab, it will cycle through other command matches such as cherry and cherry-pick. You can also tab complete remote names and branch names e.g.: git pull or<tab> ma<tab> tab completes to git pull origin master.

More information can be found at https://github.com/dahlbyk/posh-git

Installation

Prerequisites

Open a powershell window by searching for powershell in the start menu or by typing it in the address bar of an explorer window as shown in the screenshot below.

Before installing posh-git make sure the following prerequisites have been met.

  1. PowerShell 5.0 or higher. Check your PowerShell version by executing $PSVersionTable.PSVersion.

  2. Script execution policy must be set to either RemoteSigned or Unrestricted. Check the script execution policy setting by executing Get-ExecutionPolicy. If the policy is not set to one of the two required values, run PowerShell as Administrator and execute:

    Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm

  1. Git must be installed and available via the PATH environment variable. Check that git is accessible from PowerShell by executing git --version from PowerShell. If git is not recognized as the name of a command verify that you have Git installed. If not, follow the installation guide for Git. If you have Git installed, make sure the path to git.exe is in your PATH environment variable.

Installing posh-git via PowerShellGet

Execute the command below to install from the PowerShell Gallery:

PowerShellGet\Install-Module posh-git -Scope CurrentUser

You may be asked if you trust packages coming from the PowerShell Gallery. Answer yes to allow installation of this module to proceed.

Using posh-git

After you have installed posh-git, you need to configure your PowerShell session to use the posh-git module.

The first step is to import the module into your PowerShell session which will enable git tab completion. You can do this with the command Import-Module posh-git. Make sure no errors are reported.

You do not want to have to manually execute the Import-Module command every time you open a new PowerShell prompt. Let's have PowerShell import this module for you in each new PowerShell session. We can do this executing Add-PoshGitToProfile -AllHosts to make posh-git available in all your PowerShell hosts (console, ISE, etc).

Testing installation

Open a new powershell window first to make sure that posh-git is being reloaded.

Traverse to a directory where you can create a git test repository. For example your desktop:

cd ~/Desktop

Create a directory and initialize a git test repository:

mkdir hello_git
cd hello_git
git init

Now if you execute a git status you should see some posh-git magic as shown below:

All good to go

results matching ""

    No results matching ""