How to make WSL2 even faster, with fast git
Tags: wsl2, git, windows
Published: 2020-05-08 13:10:51

---
title: How to make WSL2 even faster, with fast git
published: true
description: Everybody who used wsl2 know, that git performance is really poor. I really wanted to develop on windows as my daily driver and switch from Linux completely so here is my approach to it.
tags: WSL2, Git, Windows
---

So Windows 2004 update is here, and I was really excited about this update. Because it brings WSL2 as a production-ready product to our daily drivers. With all the excitement I downloaded it, and when I did `cd` into my project I quickly realized that something is wrong. Git performance was really, really slow.

So I started searching around web and I discovered [this issue](https://github.com/microsoft/WSL/issues/4197) and it seems like this issue in only appearing in the `/mnt` directory. Sadly the only workaround I found was to move your projects into the WSL filesystem. But I knew I want something more pleasing. So I created a Symlink for it. Now, this took me a great 6 hours, to figure out all the things you need to do, so if you're stuck on the same issue, I hope my guide will help.

# 1. Create a script 📖
You need to create a batch script that will take care of the symlink. Unfortunately, you can't do a symlink from WSL to windows, which is my plan. Create a symlink from `$HOME/Code` to your User Directory. So you can start up CMD/PowerShell/Bash/WSL and `cd` right into code directory. 

Open up notepad and paste the following lines in here. Make sure you'll change you usernames
```batch
@echo off
START /B "" pushd \\wsl$\<Your WSL Version>\
rmdir C:\Users\<Your Windows Username>\Code /s /q
mklink /d C:\Users\<Your Windows Username>\Code Z:\home\<Your WSL Username>\Code
```

### *But how should I get my WSL version?*
Well, it's fairly easy. Just open up your WSL, type `cd $HOME` and then `explorer.exe .`. In the location bar type cmd like so
![Cmd in adress bar](https://dev-to-uploads.s3.amazonaws.com/i/9rh1q9zrdfgj50i3xvjw.png)
This will open WSL Filesystem in Windows explorer. Now click on the adress bar again and you should see something like this 
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/tdn5r5cau5381wz17xic.png)
The part that we need is that `Ubuntu-20.04` in my case but that could be `fedora` or `alpine` or `Ubuntu` in your case.

### *What this script does?*
Basically it will just mount your WSL as a network drive, and then it will create Windows Symlink, which will work in both Windows and WSL. Unlike the WSL symlinks which work only in WSL.

When we have our script done go to **File > Save as**, and then choose a location where you know that your script will be safe, so you don't accidentally delete it, and name it `mount_wsl.bat`.

# 2. Create a schedules task with highest privileges ⏱
Now when we have our script we need to run it every time we boot into our machine. We also need to do that with the highest privileges because you need to be an admin to make a symlink from network drive to your base drive. 

So go ahead and search for *Task Scheduler*. On the **left sidebar** you will see **Task Scheduler Library**. Click on it and on the **right sidebar** click on **Create Task...**.

Now make sure you'll give a name to your task, then write a little description and **Check "Run with highest privileges"**. Also make sure you'll change **Configure for:** To Windows10

![Win10 Scheduler](https://dev-to-uploads.s3.amazonaws.com/i/uj70giy97y3ulcbie8k5.png)

Next click on **Triggers** tab and add new trigger. This will look fairly simple, Just make sure it's like this, and click OK.

![Triggers tab](https://dev-to-uploads.s3.amazonaws.com/i/08qjcabpopaopkx7ysuo.png)

Next click on Actions add New and Select the `.bat` script we created earlier. 

# 3. Profit 🤑
Now when we restart our computer the network drive will be available in "This PC" and Code directory symlink to WSL will be in your User Directory. With significantly faster I/O Operations and git. Enjoy ✌