$ sudo apt-get update
$ sudo apt install git

# to check if it is correctly installed
$ git --version

# to set the account's default identity
$ git config --global user.email "you@example.com"
$ git config --global user.name "Your Name"

Generate ssh key following here. Adding locally hosted code to GitHub following here.

To summarize, basically do the following

$ ssh-keygen -t ed25519 -C "your_email@example.com"
# start the ssh-agent in the background
$ eval "$(ssh-agent -s)"
# <key_path> is something like ~/.ssh/id_ed25519
$ ssh-add <key_path>
# show the public key
$ cat ~/.ssh/id_ed25519.pub

Copy the shown public key and add it to SSH keys in your github account.

Git cheat sheet: here.

Having two github account

When having permission problem pushing to repo, the following helped me.

  1. Check if git configuration is correct. You might need to tell git which user is using the repo, by using the following code to set local configuration in specific repo.
    $ git config user.email "you@example.com"
    $ git config user.name "Your Name"
    
  2. You might need to add the ssh again.
    # start the ssh-agent in the background
    $ eval "$(ssh-agent -s)"
    # <key_path> is something like ~/.ssh/id_ed25519
    $ ssh-add <key_path>