Windows Git Prompt for WSL (Bash) and PowerShell
Tags: git, wsl, bash, powershell
Published: 2020-01-21 16:50:47

---
title: Windows Git Prompt for WSL (Bash) and PowerShell
published: true
description: A brand new Git prompt for PowerShell and Bash
tags: git, WSL, Bash, PowerShell
cover_image: https://thepracticaldev.s3.amazonaws.com/i/j4t1vixpx60twewndiwr.png
---

*AMA - Send me a text at +14252246702. I'll wrap up the Q&A into a dev.to blog post.*

In this tutorial, we aim to bring life to our boring old PowerShell and Bash prompt by adding a colorful Git prompt. Kinda like this one!

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/1h69715zxwhccfmwf7g8.PNG)

PowerShell is steps 1-5 and WSL (Bash) steps 6-10. Many thanks to [Gaurav Kamath](https://dev.to/gk) for pointing this out.

## Let's GOOOOO!!!

0.) [Install WSL](https://docs.microsoft.com/en-us/windows/wsl/install-win10) if you wish to have a Bash prompt. 

1.) [Install Windows Terminal](https://www.microsoft.com/en-us/p/windows-terminal-preview/9n0dx20hk701?activetab=pivot:overviewtab) for a productive terminal application and shells like Command Prompt, PowerShell, and WSL. Its main features include multiple tabs, Unicode and UTF-8 character support, a GPU accelerated text rendering engine, and custom themes, styles, and configurations.

2.) [Install Git for Windows](https://git-scm.com/download/win) so that you can use **git** from the command line.

3.) Run these two commands in your PowerShell Window to install **posh-git** which is a PowerShell module that integrates Git and PowerShell by providing Git status summary information that can be displayed in the PowerShell prompt and **oh-my-posh** which is a theme engine for Powershell 

```powershell
Install-Module posh-git -Scope CurrentUser

Install-Module oh-my-posh -Scope CurrentUser
```

4.) Within PowerShell, run `notepad $PROFILE` and add these lines to ensure the modules and theme is loaded upon startup.

```powershell
Import-Module posh-git

Import-Module oh-my-posh

Set-Theme Paradox
```

Close and reopen the PowerShell prompt and the changes should be applied. Simply navigate over to a Git repo to see changes.

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/dadibm41vyz06y8tgmw5.PNG)

5.) Set the Execution Policy to Unrestricted if you are unable to see the new theme or if it provides an error.

```powershell
Set ExecutionPolicy Unrestricted
```

6.) Install GoLang (or if you prefer [Python](https://codingpackets.com/blog/powerline-install-and-setup-for-ubuntu-bash-on-windows) for the Powerline add-in).

```bash
sudo apt install golang-go
```

Run `sudo apt update -y && sudo apt upgrade -y` if it 404s during installation

7.) Add Powerline for a beautiful and useful low-latency prompt for your shell, written in go.

```bash
go get -u github.com/justjanne/powerline-go
```

8.) Edit `~./bashrc` with VS Code or Nano (ex. code ~./bashrc or nano ~./bashrc) and add the following information ([source](https://github.com/justjanne/powerline-go#bash)

```go
GOPATH=$HOME/go
function _update_ps1() {
    PS1="$($GOPATH/bin/powerline-go -error $?)"
}
if [ "$TERM" != "linux" ] && [ -f "$GOPATH/bin/powerline-go" ]; then
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi
```

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/aliyiaxtgqse5zm8juee.png)

9.) Install a compatible [Font](https://github.com/adam7/delugia-code/releases) for the terminal.

10.) Inside of the Windows Terminal, go to Settings and add the **fontFace** line to your profile.json under the Ubuntu and PowerShell section. Below is a snippet of my Ubuntu section.

```json
    {
      "guid": "{123-38b7-51cf-b940-2309a097f518}",
      "hidden": false,
      "name": "Ubuntu",
      "source": "Windows.Terminal.Wsl",
      "fontFace": "Delugia Nerd Font"
    },
```

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/61q7g8hdl1oisr17er6k.PNG)

Finished!

Did you like this? I streamed this live on [Twitch](https://twitch.tv/mbcrump). Follow me for upcoming developer streams. 

## Recap, What did we do today?

- [x] Install Windows Terminal
- [x] Install Git for Windows
- [x] Install Posh-Git and Oh-My-Posh
- [x] Import PowerShell Modules and Set Theme
- [x] Change Execution Policy to All
- [x] Install GoLang for Windows
- [x] Run “sudo apt update” if it 404’s
- [x] Install Powerline
- [x] Edit ~/bashrc
- [x] Install Font
- [x] Add Font to Terminal Profile
- [x] Closing

## Things we learned

 - Installed the necessary Windows Terminal and Git for Windows applications, and why you would want to create a Git Prompt for WSL (Bash) and PowerShell
 - Installed modules and theme for PowerShell 
 - Installed GoLang and Powerline (Git Prompt color)
 - Install font to and configure our Terminal Profile

## Results

- A brand new Git prompt for PowerShell and Bash

## Sources

- Based on [Scott Hanselman's](https://www.hanselman.com/blog/HowToMakeAPrettyPromptInWindowsTerminalWithPowerlineNerdFontsCascadiaCodeWSLAndOhmyposh.aspx) and [Junseo Park Blog Post](https://medium.com/@junseopark/a-detailed-wsl-customization-guide-2ab19e5ca4db), Installation [docs](https://github.com/JanDeDobbeleer/oh-my-posh) and [this Awesome-WSL repo](https://github.com/sirredbeard/Awesome-WSL).