Switch the Git Clone Protocol from HTTPS to SSH
Gitlab offers several options for interacting with remote repositories: git, http, https and ssh. The first option – git – is the native transport protocol and does not encrypt the traffic. The same applies for http, rendering https and ssh the only feasible protocols if you commit and retrieve data via insecure networks. Ssh and https are also both available via the web interfaces of Github and Gitlab. In both systems you can simply copy and paste the clone URLs including the protocol. The following screenshot shows the Github version.
The simplest way to fetch the repository is to just copy the default HTTPS URL and clone it to the local drive. Git will ask you for the Github credentials.
:~/Projects$ git clone https://github.com/username/test-project.git Klone nach 'test-project' ... Username for 'https://github.com':
You will be asked for the credentials every time you interact with the Github remote repository. Per default, git stores credentials for 5 minutes. Instead of waiting so long, we can just drop the credentials and proceed with an empty cache again.
git credential-cache exit``` To make our live a little easier, we can store the username. In this example, we store this information only locally, valid for this cloned repository only. The same settings can also be applied globally. <pre class="theme:github lang:default decode:true">git config user.email "firstname.lastname@example.org" git config user.name "username"
Git will store that information locally (i.e. inside the repository) in the config file: