SSH & HTTPS#

While cloning, you are faced with two types of links: SSH and HTTPS. You may be confused and don’t know which one to copy. This section briefly explains what they are and how to set up an SSH key if you decide to use the SSH link. (If you’re new to all this Git stuff, probably just stick with HTTPS ford now.)

What are SSH & HTTPS?#

Briefly speaking, SSH and HTTPS are network protocols designed to secure communication between different computers over a network. They both use encryption algorithms to safeguard data confidentiality and protect against unauthorized access. But they work in different ways with different focuses.

  • HTTPS

    HTTPS, or Hypertext Transfer Protocol Secure, can be viewed as a secure version of HTTP protocol. It uses encryption algorithms in an extra layer to secure data confidentiality over the Internet. While communicating with a server using HTTPS, your browser first verifies the authenticity of its SSL certificate and establishes a secure connection afterwards. It requires you to use your uni ID and password every time.

  • SSH

    SSH, which stands for Secure Shell, is a cryptographic network protocol that allows secure and encrypted communication between computers over an unsecured network, usually for logging in and transferring files. The basic idea is this: when you have trusted friends, you leave a key out for them so they can get into your house when you’re not home. Git allows you to sort of do the same thing with SSH so that you don’t need to type in your uni ID and password every time.

In summary, SSH focuses on secure remote access and file transfers, while HTTPS is primarily used to secure web-based communication between browsers and websites. You can use any one of them to establish a secure connection with GitLab.

How to use SSH?#

To use HTTPS, You will need to type in your uni ID and password every time. If you want to use Git without a password, you can go for SSH, but it requires a mandatory SSH key to set up beforehand. Please follow the instructions below to set up an SSH key if you’ve decided to use it.

  1. Generate an SSH key on your local machine.

    a. Open Terminal (PowerShell in Windows)

    b. Paste the text below, substituting with your GitLab email address:

     $ ssh-keygen -t ed25519 -C "your_email@example.com"
    

    c. Keep pressing Enter until you see the key’s randomart image: ssh-gen

    d. use cd and cat command to go into the created directory in the log and check out the public key. (For Windows, use cd and type instead)

    Never show or give your private key to anyone else. Anyone with basic hacking skills can intrude into your computer easily with the private key.

    • go into that created directory (.ssh) that stores the generated keys: cd [path_in_the_log]
    • check out the public key: cat id_ed25519.pub for Linux & Mac and type id_ed25519.pub for Windows
    • copy everything from the output into the clipboard (Ctrl + Shift + C for Linux, Ctrl + C for Windows and Command + C for Mac)
  2. Paste your public key into GitLab.

    a. Click your avatar at the top right corner and select “Preferences”: ssh step 1

    b. Select “SSH Keys” in the navigation menu on the left-hand side: ssh step 2

    c. After pasting your copied public key into the “Key” box and inputting other fields such as title and expiration date, click “Add key”: ssh step 3

Well done! You’ve set up your SSH key. Now try to use the SSH link while cloning. You should be able to run it successfully now.

Further Reading#

If you’re interested in learning more about this section but encounter hard problems, you can check out the following links below:


Git Installation#

Before installation, make sure that you don’t have Git pre-installed on your computer.

Simply open Terminal (PowerShell for Windows) and type git --version. If you see something like git version 2.xx.x, you already have Git installed. You can skip this chapter and check out how to use Git in the next chapter.

Getting started#

To install Git, we will use Terminal on MacOS/Linux and its equivalent generated by the Windows Subsystem for Linux (WSL) on Windows. After installation, you can continue using Git in Terminal or IDEs with a graphical interface instead.

Simply follow the instructions with patience, and you can set everything up.

Windows#

If you’re using Windows, The most convenient way to use Git on Windows is to use Winget, a package manager for Windows. Winget is now generally pre-installed on most new Windows systems and is available on Windows Store.

If you have Winget installed, you can install Git by typing winget install --id Git.Git -e --source winget.

You can also choose to install the latest release from Windows download page. Remember to add Git into Environment Variables: Environment Variable

After installing Git, you’ll need to close and re-open your IDE!

MacOS#

If you are using MacOS, you should first type git --version at the command line to check if you have Git installed. If this is your first time using Git, macOS will prompt you to install the command line developer tools. A pop-up window will appear, asking you to install the tools. Click Install and follow the instructions.

Sometimes, however, the pop-up window may not appear. In this case, you can install the command line developer tools by typing xcode-select --install at the command line.

Another way to install Git is to use the command line and homebrew. First, make sure that you have homebrew installed. If confirmed, simply run brew install git in the command line. This should automatically install Git for you.

With the installation completed, you can double check by typing git --version at the command line. You are expected to see a similar output to git version 2.xx.x.

After installing Git, remember to close and re-open your IDE!

Linux#

This manual only covers instructions of two popular releases: Ubuntu/Debian and CentOS/Fedora.

Ubuntu#

First, use the apt package management tools to update your local package index.

$ sudo apt update

With the update complete, you can install Git:

$ sudo apt install git

You can confirm Git is installed correctly by running the following command:

$ git --version

Check if you see similar output to this:

git version 2.xx.x

If yes, you have successfully install Git. After installing Git, you’ll need to close and re-open your IDE!

CentOS/Fedora#

To install Git, you can use yum, CentOS’s native package manager, to search for and install the latest git package available in CentOS’s repositories:

$ sudo yum install git

For Fedora, you can also use another package manager called dnf:

$ sudo dnf install git

If everything goes well, downloading and installation should be fairly quick. To double-check that it is functioning properly, try running Git’s built-in version check:

$ git --version

You have successfully install Git once you see your output similar to the following log:

git version 2.xx.x

After installing Git, you’ll need to close and re-open your IDE!

bars search times arrow-up