Setting up pre-commit to work with WSL and Fork on Windows

Setting up pre-commit to work with WSL and Fork on Windows

For the tl;dr instructions, feel free to skip to the last two paragraphs.

Years ago, I used SourceTree for visualizing my git graph. At some point, SourceTree became bloated and I really didn't like the direction it went, so I looked around for alternatives. I forget if I settled on any in between, but for several years now I've been using Fork. I highly recommend it.

For my usage, I like to see what files I've changed and review the changes that are highlighted. I know there are ways to do this in my terminal, but I like this workflow as it gives me a chance to review my changes before pushing in a different window, which helps me take a new perspective.

In a previous job, I got used to using pre-commit with my Python projects to require running black, flake8, and isort. However, I was using a Mac at that job and my personal environment is on Windows, primarily using WSL. I wasn't able to get pre-commit working smoothly between WSL and Windows (where Fork is installed as there isn't a Linux version). At some point, I stopped trying and was running black, flake8, and isort manually. This meant I wasn't running them at all for some commits.

I finally got some time to dive into this and found a way to get everything set up:

Install pre-commit in Windows (not WSL). I did this through git-bash, but you should be able to do it from any terminal (or command line). You may need to install Python first if you haven't already. After installing pre-commit, you will likely have to add the install location to your path (system, not user). If you haven't set your project up to use pre-commit, you may want to manually do that in WSL first as the logs in Fork might make this step annoying if you have to clean up more than one or two issues.

You may need to restart Fork, but now you should be all set!