Learn how to – Install posh-git on Windows – PowerShell environment for Git.
As a developer or administrator, you know how much you need to keep up with in this era of a multitude of beneficial tools. Ranging from your IDE, your editor, frameworks all the way to Git. It can really get convoluted and burdensome especially for the ones venturing into this jungle. The good news is that the wonderful community continues to empower other developers with tools that do their best to make it worthwhile. This is possible by improving performance or solving particular problems that they may encounter in their career. Today we shall pour our attention on posh-git PowerShell module. Read on to get what it is all about together with checking it out on your 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, 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“. Source: Posh-Git GitHub
This looks good already and because of that we shall not waste any other minute but immediately jump into the hearth and get warmed. We shall go ahead to get posh-git installed on our Windows host.
What posh-git needs
Before embarking on getting posh-git installed, make sure the following pre-requisites have been met.
i. Windows PowerShell 5.x or PowerShell Core 6.0.
Check your PowerShell version by executing the command below:
$PSVersionTable
Also check the screenshot below for clarity
ii. On Windows, 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
The above command will ask you if you to confirm. Simply strike enter because that will accept the confirmation by default. For a better picture, check the screenshot below with the two commands executed
iii. Git must be installed and available via the PATH environment variable.
Check that git is accessible from PowerShell by executing the command below from PowerShell.
git --version
If you do not have Git installed, you can use our comprehensive guide to install it via Ansible AWX or you can download it from this site then install the EXE file the normal way by clicking “Next“ till the end as illustrated below.
Download the file
Double click on it to set installation in motion. Click “Next“
Hit “Next“
Click on “Next” after choosing the right editor for you.
Choose how you would like to use Git from the command line and Click “Next“
Set Https settings and Click “Next“
Configure Git-related settings an Click “Next“
Set preferred terminal emulator and hit “Next“
Choose the behavior of git pull then hit “Next“
Choose your preferred credential helper before hitting “Next“
Hit “Next“
Install it finally
Step 1: Installing posh-git
Before we begin, it is good to note that the installation instructions covered here applies only to version 1.x of posh-git. Now, posh-git can be installed through various means for instance through Chocolatey, PowerShellGet, Scoop or even manually. We shall begin with the simplest of them all. And that is through PowerShellGet.
Option 1: Install posh-git via PowerShellGet on Windows (Best Way)
posh-git is available on the PowerShell Gallery and can be installed using the PowerShellGet module. To get it done through this route, Start either Windows PowerShell 5.x or PowerShell Core 6.x (pwsh) as an administrator, install PowerShellGet
Install-Module PowershellGet -Force
Then execute one of the following two commands:
For a completely new installation
##A completely new installation
PowerShellGetInstall-Module posh-git -Scope CurrentUser -Force
For a updating posh-git if it has ever been installed from PowerShell Gallery
PowerShellGetUpdate-Module posh-git
Option 2: Install posh-git via Chocolatey
If you prefer to manage posh-git as a Windows package, you can use Chocolatey to install posh-git. If you do not have Chocolatey you can follow our How to install Chocolatey on Windows guide. After you are done, you can simply run the command below on your PowerShell as an administrator.
choco install poshgit
Option 3: Install posh-git via Scoop
Scoop is another popular package manager for Windows through which you can install posh-git a well. If you do not have Scoop, you can install it as follows. Open up PowerShell as an Administrator and run the commands below. Note that we need .NET Framework 4.5 or later installed.
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')
With Scoop installed, execute these commands to install posh-git and import it into your profile:
scoop install posh-git
Add-PoshGitToProfile
Step 2: Configuring posh-git
After posh-git has been installed using one of the ways described above, there are a few configuration options we need to do in order to tweak it to your liking. First, we will have to import posh-git module into your PowerShell session which will enable git tab completion. To accomplish that, open PowerShell as an administrator and run the command below:
Import-Module posh-git
Next, we will have to import posh-git from your PowerShell profile. This will prevent you from having to manually execute the Import-Module command every time you open a new PowerShell prompt. We shall therefore configure PowerShell to import this module for you in each new PowerShell session.
This can be achieved by either executing the command Add-PoshGitToProfile or by editing your PowerShell profile script and adding the command Import-Module posh-git. The simplest way in my opinion is running the Add-PoshGitToProfile command with the various options explained 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: Using posh-git
Once we are done setting up posh-git, what remains is the part we have been working hard to arrive at. It is time to put posh-git into use on our Windows computer. Fire up your PowerShell, clone any GitHub repository just to test how posh-git fares as you type away your common git commands.
git clone https://github.com/dahlbyk/posh-git
cd posh-git
The moment you navigate into the Git repository, you should see changes as shown below. It indicates the branch you are on and helps with tab completion.
References: Posh-Git GitHub Page
Epitomizing
Making your Git experience better is always welcome taking into consideration that it is a core component in your day to day tasks and activities. Knowing your branches and tracking where you are as you edit your code and commit to Git is effective and boosts performance. We hope posh-git will satisfy and solve the problems you would wish it to accommodate using its functionality and we thank you for visiting and supporting.
Git Learning Video Courses
- The Git & Github Bootcamp
- Git Going Fast: One Hour Git Crash Course
- Git Complete: The definitive, step-by-step guide to Git
- Complete Git Guide: Understand and master Git and GitHub
- Git & GitHub For Beginners – Master Git and GitHub
More guides to read:
Automate Windows Server 2019 & Windows 10 Administration with Ansible
Install and Configure GitLab on CentOS 8 / RHEL 8
Install Applications on Windows 10 | Server 2019 with winget
Leave a Reply
You must be logged in to post a comment.