DEV Community

Alberto Monraz
Alberto Monraz

Posted on

Working with GIT and WSL (Windows Subsystem for Linux)

When you install WSL in windows Git is already installed you can check it with the following command:
Note: ignore the $ symbol because is only an indicator for terminal row

$ git --version
Enter fullscreen mode Exit fullscreen mode

If you don't have Git installed for some reason execute this:

$ sudo apt-get update
$ sudo apt-get install git
$ git --version
Enter fullscreen mode Exit fullscreen mode

Now to configure Git open your distro terminal (in my case I use Ubuntu) then configure global settings (before create or login to your Github account):

$ git config --global user.name "username-on-github"
$ git config --global user.email "your-email-at-github@company.com"
Enter fullscreen mode Exit fullscreen mode

For now you can work with Git only in local environment but if you want to work Github you should create an SSH key to connect, let's do it:

First generate the key

  • [press enter] means press enter key on your keyboard
  • [enter passphrase] means you write passphrase word and then press enter key on your keyboard
$ ssh-keygen -t ed25519 -C "email-at-github@company.com"
Generating public/private ed25519 key pair.
Enter file in which to save the key (/home/yourusername/.ssh/id_ed25519): [press enter]
Created directory '/home/yourusername/.ssh'.
Enter passphrase (empty for no passphrase): [enter passphrase]
Enter same passphrase again: [enter passphrase]
Your identification has been saved in /home/yourusername/.ssh/id_ed25519
Your public key has been saved in /home/yourusername/.ssh/id_ed25519.pub
The key fingerprint is:
SHA256:XXXXXXXXXXyour-email-on-github@company.com
The key's randomart image is:
+--[ED25519 XXX]--+
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
|                 |
+----[SHA256]-----+
Enter fullscreen mode Exit fullscreen mode

Now start the ssh agent and add the private ssh key:

$ eval "$(ssh-agent -s)"
$ ssh-add ~/.ssh/id_ed25519
Enter passphrase for /home/yourusername/.ssh/id_ed25519: [enter passphrase]
Identity added: /home/yourusername/.ssh/id_ed25519 (your-email-at-github@company.com)
Enter fullscreen mode Exit fullscreen mode

Add the tool for credentials authentication on WSL (before you need install Git for windows at git webpage as a common .exe )

$ git config --global credential.helper "/mnt/c/Program\ Files/Git/mingw64/libexec/git-core/git-credential-manager-core.exe"
Enter fullscreen mode Exit fullscreen mode

Then check your private key to add later on github

$ cat /home/yourusername/.ssh/id_ed25519.pub
ssh-ed-25519 XXXXXXXXXXXXXXXXXXXXXX your-email-on-github@company.com
Enter fullscreen mode Exit fullscreen mode

Before to end add the ssh key to your github account:
1.- Login or create a github account
2.- Click on your avatar in navbar
3.- Click on settings
4.- Go to SSH and GPC Keys menu
5.- Click on new SSH key
6.- In title field insert a friendly name to identify later
7.- In key field add the private key
ssh-ed-25519 XXXXXXXXXXXXXXXXXXXXXX your-email-at-github@company.com
8.- Click on button Add SSH and then you will be noticed in your-github-email@company.com

Now you can work with Git in local and Github online, thanks for reading, good luck!

References:

github SSH generation
github SSH adding
microsoft git settings

Discussion (0)