Install posh-git on Windows-Git’s PowerShell environment

You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatturn off

As a developer or administrator, you know how much you need to keep up with in today’s age of many useful tools. From your IDE to your editor, all the way to Git build a framework. Especially for those who venture into this jungle, it is really confusing and burdensome. The good news is that this great community will continue to provide tools for other developers to make their best efforts to make them worth their money. This can be achieved by improving performance or solving specific problems they may encounter in their careers. Today, we turn our attention to the posh-git PowerShell module. Read on to get all the content and check it out on a Windows-powered computer.

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. It provides a cool PowerShell environment for Git. For example, using posh-git, PowerShell can tabulate complete git commands, such as checkout, by typing “git ch” and pressing the tab key. This will complete the “git checkout” operation of the tab character, if you keep pressing the tab character, it will cycle between other command matches (such as “cherry” and “cherry-pick”). Resources: Posh-Git GitHub

This looks pretty good, so we won’t waste any more time, but jump into the hearth and get warmer immediately. We will continue to install posh-git on the Windows host.

What posh-git needs

Before proceeding to install posh-git, please ensure that the following prerequisites have been met.

I. Windows PowerShell 5.x or PowerShell Core 6.0.

Check your PowerShell version by executing the following command:

$PSVersionTable

Also, please check the screenshot below for clarity

ii. On Windows, the script execution policy must be set to 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 an administrator and execute:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm

The above command will ask you to confirm. Just click Enter, because it will accept confirmation by default.In order to get a better picture, please check the following screenshot with the following two commandsInstall posh-git on Windows-Git's PowerShell environment

iii. Git must be installed and can be used through the PATH environment variable.

Check if git is accessible from PowerShell by executing the following command from PowerShell.

git --version

Install posh-git on Windows-Git's PowerShell environment

If you have not installed Git, you can use our comprehensive guide Install via Ansible AWX Or you can download from This site Then install the EXE file in the normal way by clicking “nextAs shown below.

Download fileInstall posh-git on Windows-Git's PowerShell environment

Double-click to start the installation. Click “nextInstall posh-git on Windows-Git's PowerShell environmentInstall posh-git on Windows-Git's PowerShell environment

hit”nextInstall posh-git on Windows-Git's PowerShell environment

Click”next“, and then select the appropriate editor for you.Install posh-git on Windows-Git's PowerShell environment

Select the way you want to use Git from the command line, and then click “nextInstall posh-git on Windows-Git's PowerShell environment

Set Https settings and click “nextInstall posh-git on Windows-Git's PowerShell environment

Configure the settings related to Git, and then click “nextInstall posh-git on Windows-Git's PowerShell environment

Set your preferred terminal emulator and click “nextInstall posh-git on Windows-Git's PowerShell environment

Select the behavior of git pull, and then click “nextInstall posh-git on Windows-Git's PowerShell environment

After clicking “nextInstall posh-git on Windows-Git's PowerShell environment

hit”nextInstall posh-git on Windows-Git's PowerShell environment

installation at lastInstall posh-git on Windows-Git's PowerShell environment

Step 1: Install posh-git

Before starting, it is important to note that the installation instructions described here only apply to the 1.x version of posh-git. Now, posh-git can be installed in many ways, such as Chocolatey, PowerShellGet, Scoop or even manually. We will start with the simplest of them. That is through PowerShellGet.

Option 1: Install posh-git via PowerShellGet on Windows (the best method)

posh-git is available on the PowerShell gallery and can be installed using the PowerShellGet module. To complete this operation by this method, please start Windows PowerShell 5.x or PowerShell Core 6.x (pwsh) as an administrator and install PowerShellGet

Install-Module PowershellGet -Force

Then execute one of the following two commands:

Perform a clean installation

##A completely new installation
PowerShellGetInstall-Module posh-git -Scope CurrentUser -Force

For updated posh-git (if installed from PowerShell repository)

PowerShellGetUpdate-Module posh-git

Option 2: Install posh-git via Chocolatey

If you want to manage posh-git as a Windows package, you can install posh-git using Chocolatey. If you don’t have Chocolatey, you can follow our “How to install Chocolatey on Windows” guide. Once you are done, you can simply run the following commands on PowerShell as an administrator.

choco install poshgit

Option 3: Install posh-git via Scoop

Scoop is another popular Windows package manager, through which you can install posh-git very well. If you don’t have Scoop, you can install it as follows. Open PowerShell as an administrator and run the following commands. Please note that we need to install .NET Framework 4.5 or higher.

Change the execution policy or enable Powershell:

Set-ExecutionPolicy RemoteSigned -scope CurrentUser

Then run the following command:

Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')

After installing Scoop, execute the following command to install posh-git and import it into your configuration file:

scoop install posh-git
Add-PoshGitToProfile

Step 2: Configure posh-git

After installing posh-git using one of the above methods, we need to perform some configuration options to adjust to our liking. First, we must import the posh-git module into the PowerShell session, which will enable git tab completion. To do this, open PowerShell as an administrator and run the following command:

Import-Module posh-git

Next, we will have to import posh-git from your PowerShell configuration file. This will prevent you from having to manually execute the Import-Module command every time you open a new PowerShell prompt. Therefore, we will configure PowerShell to import this module for you in every new PowerShell session.

This can be achieved by executing the command Add-PoshGitToProfile or by editing the PowerShell profile script and adding the command Import-Module posh-git. I think the easiest way is to run the Add-PoshGitToProfile command and explain the various options below:

##To enable posh-git to be available in just the current host, execute:
Add-PoshGitToProfile

##To enable posh-git to be available in all your PowerShell hosts-console, ISE, etc, execute:
Add-PoshGitToProfile -AllHosts

##To enable posh-git to be available for all users on the system, execute:
Add-PoshGitToProfile -AllUsers -AllHosts

##To enable posh-git to be available for all users but only for the current host
Add-PoshGitToProfile -AllUsers

Step 3: Use posh-git

Once the posh-git setup is completed, the rest is what we have been working hard to achieve. Now it’s time to use posh-git on our Windows computer. Start your PowerShell and clone any GitHub repository, just to test the posh-git cost when typing ordinary git commands.

git clone https://github.com/dahlbyk/posh-git
cd posh-git

The moment you navigate to the Git repository, you should see the changes shown below. It indicates which branch you are on and helps to complete tabs.Install posh-git on Windows-Git's PowerShell environment

references: Posh-Git GitHub page

reflect

Considering that it is a core part of your daily tasks and activities, you are always welcome to improve your Git experience. Knowing the branch and tracking your location when editing code and submitting to Git is effective and can improve performance. We hope that posh-git can use its functions to satisfy and solve the problems you want it to solve. We thank you for your visit and support.

Use Ansible to automate Windows Server 2019 and Windows 10 management

Install and configure GitLab on CentOS 8 / RHEL 8

Install apps on Windows 10 | Server 2019 with Winget

You can download this article in PDF format via the link below to support us.
Download the guide in PDF formatturn off

Sidebar