Oasist Blog

Deliver posts regarding linguistics, engineering and life at my will.

Git Installation on WSL

WSL on Windows


1. Environment

2. Install Package

  • Update Apt package manager
$ sudo apt update
  • Upgrade Apt package manager
$ sudo apt upgrade

3. Install Git

* Only if Git is not install yet after you run sudo apt update and sudo apt upgrade.

3-1. Default Package

* You will install an older version than the lastest one in this way.

  • Install Git.
$ sudo apt install git
  • Check the version of Git installed.
$ git --version

3-2. Install from a Source

* You will install the latest version of Git althogh this way takes more time Apt does not manage it.

  • Install Git.
$ sudo apt install make libssl-dev libghc-zlib-dev libcurl4-gnutls-dev libexpat1-dev gettext unzip
  • Check the version of Git installed.
$ git --version

4. Git Settings

  • Assign username and email.
$ git config --global user.name "[username]"
$ git config --global user.email "[email]"

* Omit --global to assign username and email in each project.

  • Check the configuration.
$ git config --list

5. SSH Settings

  • Generate a SSH key.
$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/[username_ubuntu]/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/[username_ubuntu]/.ssh/id_rsa.
Your public key has been saved in /home/[username_ubuntu]/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:hxbYsu6UHql6qA4tIIA7BnbVktsubFbEV6ewBQw+hmM [username_ubuntu]@DESKTOP-QDJ9F6V
The key's randomart image is:
+---[RSA 2048]----+
|     hogehoge    |
|      foobar     |
|     hogehoge    |
|      foobar     |
|     hogehoge    |
|      foobar     |
|     hogehoge    |
|      foobar     |
|     hogehoge    |
  • Create config file and take down hostname, domainm, username and path to the secret key.
vim ~/.ssh/config
Host github
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_rsa


Host gitlab
  HostName gitlab.com
  User git
  IdentityFile ~/.ssh/id_rsa

I faced some troubles here.

  1. Ubuntu refers to ~/.ssh/id_rsa while Windows detects /mnt/c/Users/[username_windows]/.ssh/id_rsa, so I had to manage both because I wanted to handle Git commands in IDE on the host OS, Windows.
  2. When I put a symbolic file of ~/.ssh/ on Ubuntu at Windows, Windows could not read it because of permission, so I failed to use Git in IDE.
  3. When I put a symbolic file of /mnt/c/Users/[username_windows]/.ssh/id_rsa on Windows to Ubuntu, Ubuntu warned that permission was too loose.

After all, I placed the same ~/.ssh on both Ubuntu and Windows, but I doubt that this is cool.
Somebody, please tell me a better solution.

6. GitHub / GitLab Settings

Register the string in the public key to GitHub or GitLab.

$ cat ~/.ssh/id_rsa.pub
ssh-rsa HOGEHOGEFOOBARhogehogefoobarHOGEHOGEFOOBARhogehogefoobarHOGEHOGEFOOBARhogehogefoobarHOGEHOGEFOOBARhogehogefoobarHOGEHOGEFOOBARhogehogefoobarHOGEHOGEFOOBARhogehogefoobarHOGEHOGEFOOBARhogehogefoobarHOGEHOGEFOOBARhogehogefoobarHOGEHOGEFOOBARhogehogefoobar [username_ubuntu]@DESKTOP-XXXXXXX

6-1. GitHub

  • Click Setting

Setting をクリック

  • Click SSH and GPG keys

SSH and GPG keys をクリック

  • Click New SSH key

New SSH key をクリック

  • Label an arbitrary name, paste the string of the public key to register.


6-2. GitLab

  • Click Setting

Setting をクリック

  • Click SSH and GPG keys

SSH keys をクリック

  • Paste the string of the public key to register.


6-3. Check Connection

  • Check the connetion with GitHub / GitLab.
$ ssh github
PTY allocation request failed on channel 0
Hi oasis-forever! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

7. Atom

IDE, such as Atom, allows us to use Git in GUI.

  • Stage: $ git add [filename]
  • Discard Changes: $ git stash (individual)
  • Stage All: $ git add -A


  • Discard All Changes: $ git stash (all)
  • Undo Last Discard: $ git stash pop


  • Click File: $ git diff
  • Stage Selection: $ git add [filename] (partly)
  • Discard Selection: $ git stash (partly)


  • Input a message and click Commit to [branch name]: git commit -m "[message]"


  • Push: git push origin [branch name]


  • Fetch: git fetch origin [branch name]
  • Pull: git pull origin [branch name]
  • Push: git push origin [branch name]
  • Push Force: git push origin [branch name] -f


8. Reference