Puget Systems print logo

https://www.pugetsystems.com

Read this article at https://www.pugetsystems.com/guides/1653
Dr Donald Kinghorn (Scientific Computing Advisor )

Note: Setup Git for PowerShell on Windows 10

Written on January 24, 2020 by Dr Donald Kinghorn
Share:

Install Official Git

Get git from the official git website git-scm.com. The download is a typical Windows installer. Note that this is maintained as a separate project called "Git for Windows". Run the installer exe. The default install options will put git on your PATH. It will run from PowerShell, CMD, and "git bash" shell based on Msys (a Linux-like Gnu dev environment for Windows from the MinGW project).

The official git site contains an online version of the book "Pro Git" by Scott Chacon and Ben Straub and published by Apress. This book contains a useful reference for PowerShell A1.9 Appendix A: Git in Other Environments - Git in PowerShell.

The "common" recommendation for command-line git on Windows is to use the "git-bash" shell. However, git works nicely from the Windows PowerShell with one small addition...

Add posh-git to Powershell

posh-git adds tab completion for git and informative color highlighted shell prompt notifications that will keep you aware of pending actions in your repository.

Check/Set Execution Policy

You will need to have "RemoteSigned" set for local PowerShell ExecutionPolicy. If you have enabled Windows "Developer Mode" you will likely have this set. Check with this command in PowerShell,

Get-ExecutionPolicy

this should return "RemoteSigned". If not then do,

Set-ExecutionPolicy -Scope CurrentUser -ExecutionPolicy RemoteSigned -Force

Install posh-git from "PowerShell Gallery"

PowerShell (version 5 or greater) has package management, and an official repository, "PowerShell Gallery".

Install-Module posh-git -Scope CurrentUser -Force

You may be asked to install "NuGet" the .Net package manager. Go ahead and say "Yes" to that.

Load the module and add git "info" to your PowerShell prompt

To use posh-git you need to import its module into PowerShell

Import-Module posh-git

To make this module load by default (recommended) do,

Add-PoshGitToProfile -AllHosts​​​​​​​

Now when you are in a directory with a git repo on your machine you will have a nice command-line git experience from PowerShell; command-completion and colorized git status information in your prompt.

Example

I use posh-git in PowerShell from a terminal in VScode. Here's a screen-shot of the repo for this post,

The last line is reminding me to push to master on GitHub ... humm, maybe I should use a branch and merge...

Happy computing! --dbk @dbkinghorn


Looking for a GPU Accelerated Workstation?

Puget Systems offers a range of workstations that are tailor-made for your unique workflow. Our goal is to provide the most effective and reliable system possible so you can concentrate on your work and not worry about your computer.

Configure a System!

Why Choose Puget Systems?


Built specifically for you

Rather than getting a generic workstation, our systems are designed around your unique workflow and are optimized for the work you do every day.

Fast Build Times

By keeping inventory of our most popular parts, and maintaining a short supply line to parts we need, we are able to offer an industry leading ship time of 7-10 business days on nearly all our system orders.

We're Here, Give Us a Call!

We make sure our representatives are as accessible as possible, by phone and email. At Puget Systems, you can actually talk to a real person!

Lifetime Support/Labor Warranty

Even when your parts warranty expires, we continue to answer your questions and even fix your computer with no labor costs.

Click here for even more reasons!

Puget Systems Hardware Partners

Tags: Programming, Git, PowerShell, Notes