Skip to content

Instantly share code, notes, and snippets.

@augustohp
Last active January 26, 2023 19:45
Show Gist options
  • Save augustohp/298343b0b4782316c4ec8179155a30b7 to your computer and use it in GitHub Desktop.
Save augustohp/298343b0b4782316c4ec8179155a30b7 to your computer and use it in GitHub Desktop.
Using Windows after 15 years of BSD (OSX, MacOS) and Unix (Debian Linux) is full of hits and misses, hopefully this will help me remembering how to set everything up.

WSL for people who do Unix

Virtualization makes obvious how many abstractions exists composing our workflow because something will break. Coming from a decade using Unix and Vim as my IDE this is what I've learned while using WSL2 and Windows.

Vocabulary

  • Windows Home: Your private user folder on Windows ($USERPROFILE% env var)
  • WSL Home: Your home inside the Linux Distro ($HOME env var)
  • WSLrc: Init script inside WSL (eg: ~/.bashrc, ~/.zshrc, ~/.bash_profile, etc)

Files

You SHOULD prefer accessing WSL files from Windows, not the other way around. Example of sharing sources files between WSL and Windows:

  • Create a ~/src inside WSL
  • Use \\wsl$\$HOME Network Folder on Windows

On WSL you have access to Windows files through /mnt/c mount, which works but is slower and some ramdom things might not work (ex: Hot reload on NodeJS apps).

Git

For an acceptable performance while using Git on WSL2, you MUST install Git on Windows. To use Windows binary inside WSL, add this to your WSLrc:

git()
{
  git.exe "$@"
}
export -f git

Git configuration SHOULD be on Windows Home (%USERPROFILE\.gitconfig), SSH information should also be there (%USERPROFILE%\.ssh\config).

@augustohp
Copy link
Author

Please don't do any of it.

Treat both systems as independent and don't try to integrate them for might end up with:

  • Your Windows home folder with a bunch of (not-so-much-unix-hidden) directories
  • Git for Windows will NOT respect all your configuration (ex: Commit editor always defaults to VScode)
  • Line endings for projects without .gitattributes will eventually get messed up
  • Permissions will be a problem sometimes. And it is always when they matter (Ex: executable bit for a guest VM)

Use WSL as you would use a remote server:

  • Need to share files? Copy them, preferably through Git.
  • Need to share configuration? Dotfiles management.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment