GitHub Desktop in Windows Subsystem for Linux (WSL2)
Greetings Developer Community š,
Itās been a long time since Iāve written something, so pardon my language pleaseš
. I wanted to pen down this coz I couldnāt properly find a tutorial or video on āHow to integrate GitHub Desktop App with Windows Subsystem for Linux (WSL2)?ā anywhere on the web. So guys, without further ado, letās get to it.
What is GitHub Desktop?
GitHub Desktop is a desktop client for GitHub (yeah, the definition was a bit shorter than I expected). For developers who arenāt comfortable with GitHub shell commands and for experienced developers who want to ease complex Git operations (resolving conflicts, cherry-picking, complex merges, etc.), GitHub Desktop is here to save the day. Itās officially available for Windows and macOS (and yes, there are some tricks to install it on Linux distros too!). If you havenāt tried it yet, head over to GitHub Desktop and see if itās your cup of tea.
What is Windows Subsystem for Linux?
Official Definition: Windows Subsystem for Linux (WSL) is a feature of Windows that allows you to run a Linux environment on your Windows machine without the need for a separate virtual machine or dual-booting. WSL is designed to provide a seamless and productive experience for developers who want to use both Windows and Linux at the same time.
Key Features:
- Install and run various Linux distributions, such as Ubuntu, Debian, Kali, and more.
- Store files in an isolated Linux file system, specific to the installed distribution.
- Run command-line tools, such as BASH
- Invoke Windows applications using a Unix-like command-line shell.
- Invoke GNU/Linux applications on Windows.
- And much moreā¦
What is WSL 2?
Official Definition: WSL 2 is the default distro type when installing a Linux distribution. WSL 2 uses virtualization technology to run a Linux kernel inside a lightweight utility virtual machine (VM). Linux distributions run as isolated containers inside the WSL 2 managed VM. WSL 2 increases file system performance and adds full system call compatibility compared to the WSL 1 architecture. Check this out to learn more about how WSL 1 and WSL 2 compare .
In simple words, WSL2 is an advanced version of WSL with better performance and compatibility.
Why Integrate GitHub Desktop with WSL2?
Letās take the case of a RubyšDeveloper (boasting my own story here š). Itās complicated to install Ruby or the Rails framework on Windows OS, leading to dozens of bugs and errors as your project grows. Even the official documentation suggests using WSL for installing Ruby. I have already installed GitHub Desktop on Windows and have been using it for a while. However, GitHub Desktop cannot directly access WSL, meaning it cannot clone a repo or execute Git commands for a project (like my Ruby on Rails project) stored in the Linux subsystem. What if I want to use GitHub Desktop to merge a branch for my Rails project? This is where the need for integration between GitHub Desktop and WSL comes into play.
How to Integrate WSL and GitHub Desktop
Assuming you already have WSL2 installed and running:
1. Download and install GitHub Desktop App:
- Visit GitHub Desktop and follow the instructions to install it.
2. Log in with your GitHub account:
- Open GitHub Desktop and sign in using your GitHub credentials.
3. Open Explorer and click on the Linux icon:
- Navigate to your WSL file system via the Linux icon in Windows Explorer.
- Navigate to your project directory in WSL file system (Here , \Ubuntu-22.04\home\mrudul\code\rails) and Copy the Path. The path would look something like this : (e.g.,
\\wsl.localhost\Ubuntu\home\username\projectfolder\
)
4.Configure GitHub Desktop with your WSL directory:
To clone a new repo into your Linux subsystem:
- In GitHub Desktop, select āFile -> Clone a repositoryā
- Paste the copied path in the Local Path(e.g.,
\\wsl.localhost\Ubuntu-22.04\home\mrudul\code\rails\test\walkthrough_awanllm_gem
). Add the link of the Repository you want to clone in Repository URL field.
- Select the āCloneā button to clone your favorite repository to your Linux Subsystem with GitHub Desktop integrated.
To initialize a local development folder (in the Linux subsystem) as a Git repo:
- Select āFile -> New Repositoryā in GitHub Desktop.
- Paste the Local path to your existing project folder (e.g.,
\\wsl.localhost\Ubuntu-22.04\home\mrudul\code\rails\test\prjct
).
To configure GitHub Desktop for an already git-initialized repo in the Linux subsystem:
- Choose āAdd an existing repositoryā in GitHub Desktop.
- Paste the Local path to your existing repo stored in Linux Subsystem (e.g.,
\\wsl.localhost\Ubuntu-22.04\home\mrudul\code\rails\first-project\firstapp
).
- If you get an error like ā The Git repository appears to be owned by another user on your machine. Adding untrusted repositories may automatically execute files in the repository.ā , click āadd an exception for this directoryā to remove this warning and finish with āAdd Repositoryā button.
5. No more steps needed š You have successfully configured GitHub Desktop for your project from the Linux subsystem.
By following these steps, you can seamlessly integrate GitHub Desktop with WSL2, enabling a smoother workflow for your development projects.
Thank you for reading! If you found this guide helpful, please share it with others who might benefit from it. Happy codingā¤ļø!