# 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](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.

![](https://981283853-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEK-j-hxx7zCDNXfjra%2F-LL4EVa4libM96oMBXqa%2F-LL4EWAFTVW3VC4fDCt-%2Fposh_git_open_powershell.png?generation=1535538772350399\&alt=media)

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`

![](https://981283853-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEK-j-hxx7zCDNXfjra%2F-LL4EVa4libM96oMBXqa%2F-LL4EWAHMZ-mjpRMtmCm%2Fposh_git_execution_policy.png?generation=1535538772313787\&alt=media)

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](https://www.powershellgallery.com/):

```
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.

![](https://981283853-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEK-j-hxx7zCDNXfjra%2F-LL4EVa4libM96oMBXqa%2F-LL4EWAJXqi-pMJJknHD%2Fposh_git_thrust_repo.png?generation=1535538772310796\&alt=media)

## 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:

![](https://981283853-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LEK-j-hxx7zCDNXfjra%2F-LL4EVa4libM96oMBXqa%2F-LL4EWALmJbcOoEdFkTQ%2Fposh_git_magic.png?generation=1535538763464350\&alt=media)

All good to go
